WO2022193768A1 - Method for executing memory read-write instruction, and computing device - Google Patents

Method for executing memory read-write instruction, and computing device Download PDF

Info

Publication number
WO2022193768A1
WO2022193768A1 PCT/CN2021/140505 CN2021140505W WO2022193768A1 WO 2022193768 A1 WO2022193768 A1 WO 2022193768A1 CN 2021140505 W CN2021140505 W CN 2021140505W WO 2022193768 A1 WO2022193768 A1 WO 2022193768A1
Authority
WO
WIPO (PCT)
Prior art keywords
memory
address
memory space
mirror
mirroring
Prior art date
Application number
PCT/CN2021/140505
Other languages
French (fr)
Chinese (zh)
Inventor
吴平宇
潘伟
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2022193768A1 publication Critical patent/WO2022193768A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/08Error detection or correction by redundancy in data representation, e.g. by using checking codes
    • G06F11/10Adding special bits or symbols to the coded information, e.g. parity check, casting out 9's or 11's
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/08Error detection or correction by redundancy in data representation, e.g. by using checking codes
    • G06F11/10Adding special bits or symbols to the coded information, e.g. parity check, casting out 9's or 11's
    • G06F11/1008Adding special bits or symbols to the coded information, e.g. parity check, casting out 9's or 11's in individual solid state devices
    • G06F11/1044Adding special bits or symbols to the coded information, e.g. parity check, casting out 9's or 11's in individual solid state devices with specific ECC/EDC distribution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/06Addressing a physical block of locations, e.g. base addressing, module addressing, memory dedication
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/06Addressing a physical block of locations, e.g. base addressing, module addressing, memory dedication
    • G06F12/0615Address space extension
    • G06F12/063Address space extension for I/O modules, e.g. memory mapped I/O
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/06Addressing a physical block of locations, e.g. base addressing, module addressing, memory dedication
    • G06F12/0646Configuration or reconfiguration
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • G06F12/10Address translation
    • G06F12/1009Address translation using page tables, e.g. page table structures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]

Definitions

  • the present application relates to the field of computers, and in particular, to a method for executing memory read and write instructions and a computing device.
  • Memory mirroring is a memory protection technology.
  • Memory mirroring-enabled memory spaces include main memory space and mirrored memory space.
  • the main memory space is used for the memory controller to read data, and the mirror memory space is used to save the backup of the data in the main memory space.
  • the computer can recover data from the mirrored memory space, improving memory stability and availability.
  • administrators pre-set parameters such as the memory space for enabling memory mirroring, the size of the mirrored memory space, and software modules based on memory mirroring protection. After the computer starts, it will implement memory mirroring through the preset memory space.
  • the embodiments of the present application provide a method and a computing device for executing a memory read and write instruction, which help to support the function of dynamic memory mirroring and thus solve the limitation of the existing memory mirroring scheme to a certain extent.
  • the technical solution is as follows.
  • a first aspect provides a method for executing a memory read/write instruction, the method comprising: receiving a memory read/write instruction, the memory read/write instruction carrying a virtual address of a target memory space; responding to a page corresponding to the virtual address
  • the table entry includes mirroring indication information, the main address and mirroring address are determined according to the virtual address, the mirroring indication information is used to identify that memory mirroring has been enabled in the target memory space, and the main address is the main memory in the target memory space
  • the physical address of the space, the mirror address is the physical address of the mirror memory space in the target memory space; according to the main address and the mirror address, execute the memory on the main memory space and the mirror memory space Operations corresponding to read and write instructions.
  • the above method enables the field in the page table entry corresponding to the virtual address to carry the mirroring indication information, thereby indicating that mirroring protection has been enabled in the memory space identified by the virtual address.
  • the mirrored memory space and the main memory space are located in different channels.
  • multiple channels can be used to parallelize the mirrored memory space and the main memory space, thereby improving read and write performance.
  • the mirrored memory space is separated from the main memory space by a distance of at least one cache line size.
  • the offset address included in the main address is determined according to the size of the cache line and the offset address included in the virtual address.
  • the main address can be determined according to the virtual address carried by the memory read and write instructions and the size of the cache line, and the computational complexity is low.
  • performing an operation corresponding to the memory read/write instruction on the main memory space and the mirrored memory space according to the main address and the mirrored address includes: responding to the main memory corresponding to the main address.
  • Both the ECC space and the ECC space corresponding to the mirror address include the mirror indication information, and according to the main address and the mirror address, execute the memory read and write instructions corresponding to the main memory space and the mirror memory space. operation.
  • the method before the receiving a memory read/write instruction, the method further includes: receiving a memory allocation request for a specified object; in response to setting a mirror flag of the specified object to a set value, allocating the specified object to the specified object.
  • the target memory space wherein, when the mirror flag is set to a set value, it indicates to allocate memory space including the main memory space and the mirror memory space for the specified object.
  • mirror protection is adopted for the memory actually requested to be allocated when the specified object is running, so as to avoid the waste of memory resources caused by the preset mirror memory that is too large, and avoid the service interruption caused by insufficient mirror memory.
  • the method further includes: sending the page table entry corresponding to the virtual address, the ECC space corresponding to the main address, and the ECC space corresponding to the mirror address, respectively. Write the mirroring indication information.
  • mirroring indication information is set in the page table entry corresponding to the specified object and the ECC space, so that each hardware of the computer can identify that the memory of the specified object is protected by mirroring.
  • the method before the receiving the memory allocation request of the specified object, the method further includes: in response to a memory mirroring instruction, modifying the mirroring flag of the specified object to the set value, the memory mirroring instruction indicating that The memory space required by the specified object enables memory mirroring.
  • each virtual page identified by the virtual address corresponds to two adjacent physical pages.
  • the method further includes: in response to a failure of the mirrored memory space, isolating the mirrored memory space; reallocating the mirrored memory space for the virtual address, and writing the data stored in the main memory space to a Reallocated mirrored memory space.
  • a device for executing memory read and write instructions has the function of implementing the first aspect or any optional manner of the first aspect.
  • the apparatus includes at least one unit, and the at least one unit is configured to implement the method provided in the first aspect or any optional manner of the first aspect.
  • the elements in the apparatus are implemented in software, and the elements in the apparatus are program modules.
  • the units in the apparatus are implemented by hardware or firmware.
  • a computing device in a third aspect, includes a processor and a memory, the memory stores at least one piece of program code, the program code is loaded and executed by the processor to implement the above-mentioned first aspect or The method provided in any optional manner of the first aspect.
  • a fourth aspect provides a computer-readable storage medium, where at least one instruction is stored in the storage medium, and when the instruction is executed on a computer, causes the computer to execute the above-mentioned first aspect or any optional manner of the first aspect. provided method.
  • a computer program product in a fifth aspect, includes one or more computer program instructions, when the computer program instructions are loaded and executed by a computer, cause the computer to execute the first aspect or the first aspect above.
  • a chip including a memory and a processor, the memory is used to store computer instructions, and the processor is used to call and run the computer instructions from the memory to execute the above-mentioned first aspect and any possible possible aspects of the first aspect. method in the implementation.
  • a computing device includes a memory management unit (memory management unit, MMU), a memory controller (memory controller, MC) and a memory;
  • MMU memory management unit
  • MC memory controller
  • the MMU is used for receiving memory read and write instructions , the memory read-write instruction carries the virtual address of the target memory space;
  • the MMU is further configured to determine the main address and the mirror address according to the virtual address in response to the page table entry corresponding to the virtual address including the mirroring indication information,
  • the mirroring indication information is used to identify that memory mirroring has been enabled in the target memory space, the main address is the physical address of the main memory space in the target memory space, and the mirroring address is the mirrored memory space in the target memory space
  • the MC is configured to perform operations corresponding to the memory read and write instructions on the main memory space in the memory and the mirror memory space in the memory according to the main address and the mirror address.
  • FIG. 1 is a schematic structural diagram of a computing device provided by an embodiment of the present application.
  • FIG. 2 is a schematic diagram of a read-write memory provided by an embodiment of the present application.
  • FIG. 3 is a flowchart of a method for executing a memory read/write instruction provided by an embodiment of the present application
  • FIG. 4 is a schematic diagram of a relationship between a primary address and a mirror address provided by an embodiment of the present application
  • FIG. 5 is a schematic structural diagram of a device for executing a memory read/write instruction provided by an embodiment of the present application.
  • a channel refers to the physical path between the memory controller and the storage medium. There is optionally one or more channels between the memory controller and the storage medium. Different channels can work serially or in parallel. In the case of multiple channels working in parallel, it can improve the bandwidth and throughput of the memory.
  • Memory address interleaving refers to an addressing method that evenly distributes memory addresses across a group of channels. For example, there are 2 channels, channel 0 and channel 1. With memory address interleaving enabled, if virtual address 32 belongs to channel 0, then virtual address 33 belongs to channel 1, virtual address 34 belongs to channel 0, and virtual address 35 belongs to channel 1, and so on. By enabling memory address interleaving, each channel can be used in parallel or in turn to perform continuous memory reading and writing, thereby reducing the time consuming of memory reading and writing and improving the efficiency of memory reading and writing.
  • a memory space with memory mirroring enabled consists of two separate physical memory spaces.
  • One physical memory space acts as the main memory space, and the other physical memory space acts as the mirror memory space.
  • the main memory space is used for reading and writing, while the mirror memory space is used to hold backups of data. If the main memory space fails, memory data can be recovered from the mirrored memory space.
  • the mirrored memory space has the same capacity as the main memory space. For example, the capacity of the main memory space is N pages, and the capacity of the mirror memory space is also N pages.
  • the mirroring indication information is the indication information provided by this embodiment for identifying whether to enable memory mirroring. Through the mirroring indication information, it is possible to distinguish whether the memory space to be accessed is a memory space with memory mirroring enabled or a memory space without memory mirroring enabled.
  • the corresponding mirroring indication information is marked for the memory space A; in the memory read-write process, when the memory management unit (memory management unit) unit, MMU) detects the mirroring indication information, the MMU will calculate the physical address of the main memory space according to the address calculation method provided in this embodiment, and when the memory controller (memory controller, MC) detects the mirroring indication information, the MC will follow the The address calculation method provided in this embodiment calculates the physical address of the mirrored memory space, so as to correctly convert the virtual address to the physical address of the main memory space and the physical address of the mirrored memory space.
  • the mirroring indication information occupies one bit in the reserved field.
  • a bit occupied by the mirroring indication information can be called the mirroring indication information field. If the bit position is set (that is, the value is 1), it indicates that the mirroring indication information is available. If the bit is not set (that is, the value is 0), it indicates that the mirroring indication information is not available. .
  • the mirroring flag is a flag provided in this embodiment for identifying whether to allocate a memory space for enabling memory mirroring. For example, when the mirroring flag is set to a set value (such as 1), it indicates that the allocation of memory space includes enabling memory mirroring. When the mirror flag is not set to the set value, it means that only the memory space of the size specified by the request is allocated. For example, process A sends a memory allocation request indicating that process A is allocated a page of memory space. If the mirror flag of process A is 1, two physical pages are allocated for process A, one physical page is the main memory space, and the other physical page is the mirror memory space. If process A's mirroring flag is 0, process A is allocated a physical page.
  • a set value such as 1
  • process A sends a memory allocation request indicating that process A is allocated a page of memory space. If the mirror flag of process A is 1, two physical pages are allocated for process A, one physical page is the main memory space, and the other physical page is the mirror memory space. If process A's mirror
  • the mirror flag is, for example, an input parameter of a memory allocation function.
  • the mirroring flag instructs memory space to be allocated with memory mirroring enabled when the memory allocation function is executed.
  • the memory allocation function is the kmalloc function
  • the mirror flag is a get free page (get free pages, GFP) allocation flag (also called the memory allocation flag or the flags parameter) of the kmalloc function.
  • the memory allocation function is the vmalloc function
  • the image flag is a virtual address space (virtual memory area, VMA) flag in the vmalloc function.
  • a cache is hardware that caches the contents of memory.
  • a cache line is the basic unit of a cache.
  • Cache line size refers to the size of a cache line. When the computer accesses the memory, it will migrate the data in the memory to the cache according to the size of the cache line. For example, the cache line size is N bytes, and when the computer accesses the memory, at least N bytes of data in the memory are migrated to the cache at a time.
  • ECC space refers to the area in memory where checksums in ECC technology are kept.
  • ECC is an instruction error correction technique.
  • the basic principle of ECC is that each time data is written into the memory, the ECC code uses a special algorithm to calculate the data, and the result is called check bits. Then add all the check bits together to get the checksum (checksum), and the checksum is stored in memory along with the data.
  • checksum checksum
  • the same algorithm is used to calculate the checksum again and compare it with the previous calculation result. If the result is the same, it means that the data is correct, otherwise it means that there is an error, then the error is logically separated and notified. system.
  • ECC can correct the error without affecting system operation.
  • the memory failure is mild, the application process will be terminated or crashed abnormally, and some services will be interrupted. In severe cases, the operating system (OS) will be down, and all services will be interrupted.
  • OS operating system
  • RAS availability and diagnostic
  • mission critical also requires memory mirroring technology to further reduce memory failures and business interruptions possibility.
  • the memory space is organized in the manner of the main memory space and the mirrored memory space, and is allocated to the application in units of a main memory space and a mirrored memory space. When one memory space in the main memory space and the mirrored memory space fails, the system can restore data from another memory space, thereby avoiding application or system downtime.
  • the cost of the current memory mirroring technology is relatively high, and when the preset mirror memory space is insufficient, OOM will still occur, resulting in service interruption. Modifying the mirror space must be restarted (reboot) to take effect, and will also interrupt services.
  • Some researches try to implement memory mirroring using full mirror mode, partial mirror mode, address range mirroring, etc.
  • the memory mirroring relationship in these modes is fixed, which cannot meet the software's dynamic mirroring management requirements for key business memory modules.
  • OS support is required to fully utilize the address range image; and, firmware-OS (Firmware-OS) needs to be provided.
  • the OS must interact with the Basic Input Output System (BIOS) to determine the mirror region information; and, to modify the mirror region size (region size), the operating system must be restarted to take effect; and the application process cannot obtain the mirror image Protect.
  • BIOS Basic Input Output System
  • the embodiment of the present application provides a dynamic memory mirroring scheme, which only adopts mirror protection for the memory actually allocated by the OS or key business processes, and can avoid the preset memory under the condition that the memory failure will not lead to interruption of the business.
  • Excessive mirroring memory leads to waste of expensive memory resources, and it can also avoid the serious consequences of insufficient mirroring space in the preset memory, failure of mirroring protection, or service interruption caused by OOM.
  • the existing mirroring solution cannot solve the problem of allocating new mirroring space after the mirroring memory fails, resulting in that the business continuity cannot be well guaranteed; while in the embodiment of the present application, when the dynamic mirroring memory fails, the system can additionally allocate a new mirroring space. Mirror memory and isolate faulty memory to ensure business continuity.
  • FIG. 1 is a schematic structural diagram of a computing device provided by an embodiment of the present application.
  • the computing device 100 shown in FIG. 1 is used to execute the method provided by the embodiment of the present application.
  • Computing device 100 includes processor 101 , memory 102 , and network interface 103 .
  • the processor 101 includes a CPU, an MMU, and an MC.
  • the CPU includes a CPU execution unit and an MMU.
  • a CPU execution unit refers to a hardware unit in a CPU that processes data or computer program instructions.
  • a CPU execution unit is one or more CPU cores. In the process of executing mirrored memory read and write, the CPU execution unit is used to generate and send memory read and write instructions.
  • the MMU is used to translate virtual addresses to physical addresses. Specifically, as shown in FIG. 2 , after the CPU execution unit sends the memory read and write instructions, the MMU intercepts the memory read and write instructions, and performs address conversion, that is, converts the virtual addresses in the memory read and write instructions into physical addresses. After that, the MMU sends the address-translated instruction to the MC. The action of MMU address translation is also called translation.
  • the MMU uses page tables to implement virtual to physical address translation.
  • the physical address obtained by the MMU address conversion includes at least one of a main address or a mirror address. For example, in some embodiments, as shown in FIG.
  • the MMU sends the main address and the mirror address to the MC; the MC receives the main address and the mirror address sent by the MMU, and performs mirror read and write operations on the memory according to the main address and the mirror address .
  • the MMU sends the main address and the virtual address to the MC, the MC receives the main address and the virtual address sent by the MMU, and the MC determines the mirror address according to the main address and the virtual address. After that, the MC performs mirrored read and write operations on the memory according to the main address and the mirrored address.
  • the MMU is usually set up inside the CPU.
  • the page table is stored in memory. Each row in the page table corresponds to a page in the virtual storage space. The row contains the address of the physical memory page corresponding to the virtual memory page, the access authority of the page, and the buffering characteristics of the page. . Each entry in the page table is called a page table entry.
  • the MC is used to control the memory, and the data exchange between the memory and the CPU is realized through the MC. Specifically, the MC is used to access the memory according to the physical address carried by the instruction sent by the MMU. In the case of reading data, the MC obtains the data from the location corresponding to the physical address in the memory, and returns the data to the CPU. In the case of writing data, the MC writes the data to the location corresponding to the physical address.
  • the MC judges whether the memory read/write command is a mirror read/write command, and judges whether the mirror indication information field in the ECC is set; if the memory read/write command is a mirror read/write command and the ECC If the medium mirror indication information field is set, the MC performs mirror read and write operations, that is, perform read data operations or write data operations on the main memory space and the mirror memory space at the same time. If the memory read/write command is not a mirror read/write command and the mirroring indication information field in the ECC is set, the MC refuses to execute the memory read/write command, thereby preventing the mirrored memory from being illegally accessed.
  • the positional relationship between the MC and the CPU includes various cases.
  • the MC is provided inside the CPU, that is, the MC is integrated with the CPU.
  • the MC is provided outside the CPU, that is, the MC is provided separately from the CPU.
  • the MC in the processor 101 is arranged inside the CPU, and the MC in the processor 105 is arranged outside the CPU.
  • the memory 102 includes memory.
  • Memory includes ECC space.
  • the memory 102 is, for example, a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, or a random access memory (RAM) or a device that can store information and instructions.
  • ROM read-only memory
  • RAM random access memory
  • Other types of dynamic storage devices such as electrically erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disk storage, optical disks storage (including compact discs, laser discs, compact discs, digital versatile discs, Blu-ray discs, etc.), magnetic disk storage media, or other magnetic storage devices, or capable of carrying or storing desired program code in the form of instructions or data structures and capable of Any other medium accessed by a computer without limitation.
  • EEPROM electrically erasable programmable read-only memory
  • CD-ROM compact disc read-only memory
  • optical disks storage including compact discs, laser discs, compact discs, digital versatile
  • computing device 100 also includes bus 104 .
  • bus 104 is a memory bus or a system bus.
  • the processor 101 , the memory 102 and the network interface 103 are connected through a bus 104 .
  • the bus 104 is used to transfer information between the aforementioned components.
  • computing device 100 also includes an input-output interface 106 .
  • An input-output interface 106 is connected to the bus 104 .
  • the input-output interface 106 is used for connecting with an input device, and receiving commands or data involved in the following method embodiments input by a user through the input device, such as memory mirroring instructions.
  • Input devices include, but are not limited to, keyboards, touch screens, microphones, mice, or sensing devices, among others.
  • the input-output interface 106 is also used to interface with output devices.
  • the input-output interface 106 outputs the intermediate results and/or final results generated by the processor 301 by executing the following method embodiments, such as data read from the memory, through the output device.
  • Output devices include, but are not limited to, displays, printers, projectors, and the like.
  • the processor 101 implements the methods in the above embodiments by reading program codes stored in the memory 102, or the processor 101 implements the methods in the above embodiments by using internally stored program codes.
  • the processor 101 implements the method in the above embodiment by reading the program code stored in the memory 102
  • the memory 102 stores the program code for implementing the method provided by the embodiment of the present application.
  • FIG. 3 is a flowchart of a method for executing a memory read/write instruction provided by an embodiment of the present application.
  • the method shown in FIG. 3 includes the following steps S301 to S303.
  • Step S301 the computing device receives a memory read and write instruction.
  • the memory read and write instructions are used to instruct a data read operation or a write data operation to the target memory space.
  • the target memory space refers to the space that needs to be accessed currently in the memory of the computing device.
  • Memory read and write instructions carry the virtual address of the target memory space.
  • a memory read/write instruction includes a destination address field, and the content of the destination address field includes a virtual address of the target memory space.
  • the virtual address of the target memory space includes the base address and the offset address.
  • the base address in the virtual address also called the page number, is used to identify the corresponding virtual page.
  • the offset address in the virtual address also called the page offset, is used to identify the location inside the virtual page.
  • a virtual page is also called a logical page, which is a concept relative to a physical page.
  • Step S302 in response to the page table entry (page table entry, PTE) corresponding to the virtual address including the mirroring indication information, the computing device determines the main address and the mirroring address according to the virtual address.
  • the page table is used to record the physical address corresponding to the virtual address, and the page table also includes a reserved field.
  • the mirroring indication is used to identify that the target memory space has memory mirroring enabled.
  • the mirroring indication information in the page table entry is located in the reserved field of the page table entry. For example, one or more bits are enabled in the reserved field of the page table entry as the mirror indication information field. If the mirroring indication information field in the page table entry is set (that is, the page table entry includes mirroring indication information), it means that memory mirroring is enabled in the target memory space. If the mirroring indication information field in the page table entry is not set (that is, the page table entry does not include mirroring indication information), it means that memory mirroring is not enabled in the target memory space.
  • the PTE of the ARM architecture includes an upper attribute field, an output block address field, and a lower attribute field, and the upper attribute field includes a reserved for software use field, A bit in a field reserved for software use is enabled as a mirror indication field.
  • the MMU can identify whether dynamic mirroring is enabled for the virtual address through whether the page table entry carries the mirroring indication information, thereby solving the problem that the MMU does not support translating virtual addresses into real mirroring addresses.
  • the main address is the physical address (Physical Address, PA) of the main memory space in the target memory space.
  • the main address includes the base address and the offset address.
  • the base address corresponds to the page number of the physical page.
  • a specific main address is simplified in the form of “Pri+number” in FIG. 4, for example, each of Pri0, Pri1...Pri4095 in FIG. 4 represents a specific main address.
  • Pri is the abbreviation of "Primary (main, referring to the main memory space)".
  • the mirror address is the physical address of the mirror memory space in the target memory space.
  • the mirror address includes the base address and the offset address.
  • a specific mirror address is simplified in the form of “Sec+number” in FIG. 4 .
  • each of Sec0 , Sec1 . . . Sec4095 in FIG. 4 represents a specific mirror address.
  • Sec is the abbreviation of "Secondary (standby, referring to the mirrored memory space)".
  • the mirrored memory space is separated from the main memory space by a distance of one or more cache line sizes.
  • the mirrored memory space is separated from the main memory space by a distance of one cache line size.
  • the primary address is separated from the mirrored address by a distance of at least one cache line size.
  • the primary address is separated from the mirrored address by a distance of one cache line size.
  • the primary address Pri0 and the backup address Sec0 have a mirror relationship
  • the primary address Pri63 and the backup address Sec63 have a mirror relationship
  • the primary address Pri0 and the backup address Sec0 are separated by a distance of a cache line size
  • the primary address Pri63 and the backup address Sec63 is one cache line size apart. In this way, the address calculation method is made as simple as possible, and the implementation complexity is reduced.
  • the relationship between the mirror address and the master address satisfies Equation 1 below.
  • Secondary_PA represents the mirror address
  • Primary_PA represents the primary address
  • CacheLine_Size represents a cache line size.
  • the main address Pri0 is in the first byte of Cache Line0
  • the offset address included in the main address is determined according to the cache line size and the offset address included in the virtual address.
  • PA represents the physical address
  • Page_Base_PA represents the base address of the physical page
  • Offset_In_VA represents the offset address in the physical page.
  • Offset_In_Memory Offset_In_VA+Cache_Line_Size*[INT(Offset_In_VA/Cache_Line_Size)];
  • Offset_In_Memory represents the offset address of the main address
  • Offset_In_VA represents the offset address in the virtual address
  • Cache_Line_Size represents the size of the cache line
  • INT represents the rounding operation.
  • Primary_PA Page_Base_PA+Offset_In_VA+Cache_Line_Size*[INT(Offset_In_VA/Cache_Line_Size)];
  • Primary_PA represents the main address
  • Page_Base_PA represents the base address of the physical page
  • Offset_In_VA represents the offset address in the virtual address
  • Cache_Line_Size represents the cache line size
  • INT represents the rounding operation.
  • each virtual page identified by the virtual address corresponds to two adjacent physical pages.
  • two adjacent physical pages are, for example, the address of the last position in one physical page is adjacent to the address of the first position in another physical page.
  • the OS allocates a block of memory space with contiguous addresses in units of pages.
  • this embodiment performs memory mirroring in units of pages. When allocating mirrored memory, memory space is allocated in units of two adjacent consecutive physical pages. For example, referring to FIG.
  • the size of a page is 4KB
  • the virtual page is a page identified by virtual address 0 to virtual address 4095
  • the target memory space is physical page 1 identified by physical address 0 to physical address 4095, physical address 4096 to Physical page 2 identified by physical address 8191.
  • a physical page includes one or more main memory spaces and one or more mirrored memory spaces.
  • physical page 1 includes both main memory space (cache line 0 main, cache line 2 main) and mirror memory space (cache line 1 mirror, cache line 3 mirror).
  • the main memory space and the mirror memory space are interleaved in a physical page.
  • the distance between the main memory space and the mirror memory space that are mirrored to each other in a physical page is one cache line size.
  • Step S303 The computing device performs operations corresponding to the memory read and write instructions on the main memory space and the mirrored memory space according to the main address and the mirrored address.
  • memory address interleaving is enabled while the dynamic mirroring function is enabled. For example, enable 2way Channel Interleave.
  • the mirrored memory space and the main memory space are in different channels.
  • the memory space identified by the mirror address primary0 and the memory space identified by the primary address primary0 are located in different channels.
  • the mirrored memory space and the main memory space are located in different channels, the mirrored memory space and the main memory space are physically independent of each other, and the memory controller can use multiple channels to Mirror memory space and main memory space to improve read and write performance.
  • the above memory read and write instructions are write instructions, the main memory space is located in channel 0, and the mirror memory space is located in channel 1.
  • the memory controller writes data to the main memory space in channel 0, it writes data to the mirror memory space in channel 1. data input.
  • the read and write performance is higher.
  • the mirrored memory space and the main memory space can read and write data at the same time, it is ensured that the mirrored memory space and the main memory space data are kept synchronized, and errors caused by inconsistent data saved in the mirrored memory space and the main memory space are avoided.
  • the computing device determines whether the ECC space corresponding to the primary address includes mirroring indication information, and determines whether the ECC space corresponding to the mirroring address includes mirroring indication information; in response to the ECC corresponding to the primary address Both the space and the ECC space corresponding to the mirrored address include mirroring indication information, and the computing device performs operations corresponding to the memory read and write instructions on the main memory space and the mirrored memory space according to the main address and the mirrored address.
  • the action of judging whether the ECC space includes mirroring indication information is specifically performed by the MC in the computing device. Specifically, when the MC receives the memory read/write command, it determines whether the memory read/write command is a mirror read/write command. If the memory read/write command is a mirror read/write command, the MC determines the mirror address, and accesses the ECC space corresponding to the main address and For the ECC space corresponding to the mirror address, the MC judges whether the ECC space corresponding to the main address and the ECC space corresponding to the mirror address both include mirror indication information.
  • both the ECC space corresponding to the main address and the ECC space corresponding to the mirror address include mirror indication information
  • the MC performs mirror read and write operations, that is, perform read data operations or write data operations on the main memory space and the mirror memory space at the same time. If the ECC space corresponding to the primary address does not include mirroring indication information, or the ECC space corresponding to the mirroring address does not include mirroring indication information, the MC determines that the access to the mirrored memory is illegal, and the MC refuses to perform mirroring read and write operations.
  • one or more bits are enabled in the ECC space as a mirror indication information field for the MC to identify a memory space in which mirror memory is enabled. If the mirroring indication information field in the ECC space is set (that is, the ECC space includes mirroring indication information), it means that memory mirroring is enabled in the target memory space. If the mirroring indication information field in the ECC space is not set (that is, the ECC space does not include mirroring indication information), it means that memory mirroring is not enabled in the target memory space. For example, referring to FIG. 4, the primary address Pri0 is located in the cache line CacheLine0, and the mirror address Sec0 is located in the cache line CacheLine1.
  • ECC space corresponding to CacheLine0 and the ECC space corresponding to CacheLine1 both include mirroring indication information, mirroring read and write operations (such as simultaneous data writing) are allowed to the memory space marked by the primary address Pri0 and the memory space marked by the mirror address Sec0.
  • the enabling field in the page table entry corresponding to the virtual address carries mirroring indication information, thereby indicating that mirroring protection has been enabled in the memory space identified by the virtual address.
  • the above-mentioned processing flow of reading and writing the mirrored memory is implemented by the MMU and the MC.
  • the MMU is used to perform a translation process flow from a virtual address to a physical address on the dynamic mirror memory.
  • the MMU detects that the mirror indication information field in the page table entry corresponding to the virtual address is 1, the MMU calculates the physical address of the main memory space according to the above formula 2.
  • the processing flow of the MC performing mirror memory read and write includes the following steps 1 to 3.
  • Step 1 Reject non-"mirror read and write” commands.
  • the MC detects whether the content of the mirror indication information field in the ECC corresponding to the destination address of the memory read/write instruction is 1.
  • the mirror indication information field is 1, if the MC receives a non-mirrored read/write command, the MC refuses to execute the command and returns an illegal access, thereby ensuring that mirror-protected pages can only be used for mirror-protected operations.
  • the page allocated as mirrored memory the corresponding ECC mirroring indication information is 1; the page fault interrupt function of the OS initiates the ECC mirroring indication information field setting operation when the physical page is allocated; when the physical page is released , the physical page recovery function of the OS initiates the zero-clearing operation of the mirror indication information field of the ECC.
  • the MC identifies whether the dynamic mirroring function is enabled in the physical memory through the mirroring instruction information field of the ECC, and can distinguish between ordinary memory read and write instructions and mirrored memory read and write instructions, thus solving the problem that the MC cannot support dynamic memory mirroring.
  • Step 2 The MC executes normal mirror read/write commands.
  • the destination address in the "mirror read and write" command received by the MC is the primary address Pri_PA translated by the MMU through formula 2.
  • the MC calculates the mirror address Sec_PA according to formula 1, and simultaneously initiates an operation (read/write) specified by the instruction to the main memory space and the mirror memory space, thereby ensuring the consistency of the main address and mirror address writing.
  • the MC that receives the command is responsible for interacting with the MC to which the mirror address Sec_PA belongs to complete the corresponding command operation.
  • Step 3 If the MC encounters an error when executing the memory read/write command, follow steps 3, 4, 5, 6, and 7 in the following dynamic mirror memory fault handling process.
  • the computing device before receiving the memory read/write instruction, the computing device receives a memory allocation request for the specified object; in response to the specified object's mirroring flag being set to a set value, the computing device allocates the target memory space for the specified object.
  • Specified objects refer to software modules that are allowed to occupy memory space in the computer.
  • specified objects include, but are not limited to, a process, a kernel, a portion of a VMA segment of a process, a portion of a module in the kernel, and the like.
  • a memory allocation request indicates to allocate memory space for the specified object.
  • different types of designated objects have different mirror marks. For example, the kernel's mirror flag is different from the process' mirror flag.
  • mirror protection is adopted for the memory actually requested to be allocated when the specified object is running, so as to avoid the waste of memory resources caused by the preset mirror memory that is too large, and avoid the service interruption caused by insufficient mirror memory.
  • the computing device after receiving the memory allocation request for the specified object, the computing device writes mirror indication information to the page table entry corresponding to the virtual address, the ECC space corresponding to the main address, and the ECC space corresponding to the mirror address, respectively. For example, in the process of allocating mirrored memory, the computing device uses the mirroring indication information field in the page table entry corresponding to the virtual address, the mirroring indication information field in the ECC space corresponding to the main address, and the mirroring indication in the ECC space corresponding to the mirror address. Information fields are all set to 1.
  • mirroring indication information is set in the page table entry corresponding to the specified object and the ECC space, so that each hardware of the computer can identify that the memory of the specified object is protected by mirroring.
  • the dynamic mirror memory allocation process flow is implemented by modifying the memory management module of the OS. Specifically, modify the memory allocation function of the OS memory management module. In the memory allocation function, add a module that sets the mirroring indication information of the PTE to 1 when processing mirrored memory allocation, indicating that mirroring protection is enabled for this memory space. Modify the page fault interrupt processing function of the OS memory management module, and add a module for mirroring memory allocation to physical pages in the page fault interrupt processing function. When the page fault interrupt processing function detects that the mirroring indication information of the PTE is 1, it also sets the mirroring indication information of the ECC corresponding to the actually allocated physical page to 1, so that the memory controller can identify and process according to the requirements of dynamic mirroring memory.
  • the processing flow for allocating virtual addresses by the dynamic mirror memory allocation function includes the following steps 1 to 3.
  • Step 1 The OS allocates a new virtual address space for the process.
  • GFP_MIRROR kernel mode
  • VM_MIRROR user mode
  • GFP_MIRROR kernel state
  • GFP_MIRROR kernel mode processes
  • VM_MIRROR is a VMA flag
  • VM_MIRROR applies to user-mode processes.
  • Added GFP_MIRROR (kernel mode) and vma new flag VM_MIRROR (user mode) through the gfp allocation flag to solve the problem that the memory allocation function cannot support the management of memory dynamic mirroring, and support the dynamic mirroring programming interface.
  • the system calls the brk or do_map function to allocate a new virtual address space.
  • Step 2 The OS adds a page table entry corresponding to the virtual address in the process page table.
  • a page table entry is allocated for the newly added address space in the page table.
  • the base address of the page is recorded in the page table entry, and the corresponding physical page base address is empty.
  • Step 3 The OS sets the mirroring indication information field of the newly added PTE to 1.
  • the MMU calls formula 2 to correctly translate the virtual address to the main address; at the same time, the page fault interrupt handler also allocates two consecutive physical pages for this virtual address, the base of the first physical page. The address is recorded into the physical address of the page table entry.
  • the processing flow of allocating physical pages by the dynamic mirroring memory function includes the following steps 1 to 3.
  • Step 1 The OS determines whether the mirror indication information field of the page table entry corresponding to the virtual address is 1.
  • the OS allocates two consecutive physical pages.
  • the OS allocates a physical page according to the original process.
  • Step 2 The OS allocates two consecutive physical pages to the virtual address.
  • two consecutive physical pages are searched in the free physical page space, and the base address of the first physical page in the two consecutive physical pages is recorded in the physical address of the page table entry corresponding to the virtual address. If there are not two contiguous physical pages, try to move the data held in some physical pages, thus constructing two contiguous physical pages, and allocate the constructed two contiguous physical pages.
  • Step 3 The OS sets the mirror indication information field corresponding to the ECC to 1.
  • the OS records the base address of the newly allocated physical page into the physical address field of the page table entry.
  • the underlying interface is called to set the mirror indication information field of the ECC corresponding to the newly allocated physical page to 1, to ensure that the MC also manages the physical page according to the dynamic mirror memory.
  • the allocated two physical pages are marked as reserved (Reserved) at the same time to avoid repeated allocation.
  • a module for reclaiming physical pages of mirrored memory is added to the memory reclamation processing function of OS memory management.
  • the processing flow of the dynamic mirror memory recycling function includes the following steps 1 to 3.
  • Step 1 Determine whether the mirror indication information field of the page table entry corresponding to the virtual address is 1.
  • the mirror indication information field of the page table entry is 1, indicating that dynamic memory mirroring is enabled in the memory space corresponding to the virtual address, two consecutive physical pages corresponding to the physical address field are reclaimed.
  • the mirror indication information field of the page table entry is 0, a physical page corresponding to the physical address field in the page table entry is reclaimed according to the original process.
  • Step 2 The page recycling function sets the mirror indication information field corresponding to the ECC to 0.
  • the value carried by the physical address field of the corresponding page table entry is obtained according to the virtual address.
  • the underlying interface is called to set the mirroring indication information field of the ECC of two consecutive physical pages corresponding to the physical address to 0, so as to ensure that the MC manages the physical pages according to ordinary memory.
  • Step 3 The page reclaim function reclaims the home page and the mirror page corresponding to the physical address.
  • the page recycling function clears the physical address field of the page table entry corresponding to the virtual address; puts the two physical pages back into the free page linked list for allocation.
  • the method before receiving the memory allocation request for the specified object, the method further includes: in response to the memory mirroring instruction, the computing device modifies the mirroring flag of the specified object to a set value.
  • the memory mirroring instruction instructs to enable memory mirroring for the memory space required by the specified object.
  • the memory mirroring instruction is triggered, for example, by the operation of the administrator.
  • Memory mirroring instructions include the identification of the specified object.
  • the memory mirroring instruction includes the process ID (Process ID, PID) of the process.
  • the configuration and command flow includes a kernel image protection flow and a process memory image protection flow.
  • the kernel image protection process refers to adding new configuration items to the existing system configuration file, or defining a new configuration file, which is used to define those parts of the kernel to enable dynamic memory image protection.
  • image protection is allocated to the kernel according to the configuration. physical page, the process includes the following steps 1 to 3.
  • Step 1 The operating system starts (OS Boot) and parses the configuration about the protection of the kernel image in the configuration file.
  • Step 2 According to the configuration file, allocate mirrored physical pages to modules in the kernel that need mirroring protection.
  • Step 3 Allocate mirrored physical pages for the kernel during operation.
  • the mirrored physical pages are allocated for the new memory requirements of the kernel; or, when the memory fails, the faulty pages are isolated and new mirrored physical pages are allocated.
  • the process memory image protection process includes the following steps 1 to 3.
  • the following mirrorable commands are the above memory mirroring commands.
  • Step 1 Start the process with the mirrorable command and mirror the memory of the process.
  • MML #mirroable program
  • mirroable sets task_struct->mirrorable to true (True), the process memory enables mirror protection, and the mirror indication information fields of the page table entries corresponding to the allocated virtual addresses are all set to 1.
  • Step 2 After the process starts, run the mirrorable command to mirror the memory of the process.
  • MML #mirroable pid
  • the mirroable command suspends the pid process first; modifies the pid process task_struct->mirrorable to be true (True); sets all the mirror indication information fields of the page table entries corresponding to all virtual addresses of the pid process to 1; allocates physical pages for the pid process Create a new mirrored physical page, copy the existing physical page data to the mirrored physical page, refresh the physical address corresponding to the virtual address with the physical address of the mirrored physical page; release the original unmirrored physical page; activate the pid process to continue running.
  • Step 3 Manage process memory mirroring through the programming interface
  • the OS can support dual kernels, you can start a memory mirror to protect the new kernel through the mirrorable command, and then hand over all the business to the new kernel for management, and release the old kernel without mirror protection, so that you can run ) switches the kernel to an image-protected state.
  • the computing device isolates the mirrored memory space in response to the above-mentioned fault in the mirrored memory space; the computing device reallocates the mirrored memory space for the virtual address, and the computing device writes the data stored in the main memory space to the reallocated mirrored memory space .
  • the computing device selects a memory space with the same capacity as the main memory space from the free and available memory space in the memory as the reallocated mirror memory space.
  • the computing device also tags the failed mirrored memory space. Flags are used to indicate that the mirrored memory space is in a failed state. When the computer subsequently allocates memory, it will not allocate the marked memory space, thereby avoiding problems caused when the faulty mirrored memory space is allocated.
  • the dynamic mirror memory fault handling process includes the following steps 1 to 7.
  • Step 1 When the system is running normally, faults are found through automatic memory inspection, or faults are encountered when accessing memory.
  • Step 2 The hardware of the computing device determines the faulty page in the memory, triggers an interrupt, and proceeds to Step 3 and Step 4. Specifically, when the MC encounters an uncorrectable error (Uncorrectable Error, UCE) while executing the mirror read/write instruction, it notifies the OS through an interrupt to perform data recovery and fault page isolation.
  • UCE Uncorrectable Error
  • Step 3 The computing device restores data from the normal page.
  • Step 4 The OS or virtual machine monitor (Virtual Machine Monitor, VMM) of the computing device isolates the fault page, proceeds to step 5, and proceeds to step 6 or step 7.
  • VMM Virtual Machine Monitor
  • Step 5 The OS or VMM of the computing device reallocates the mirror page.
  • Step 6 If the number of exceptions is lower than the threshold or the available memory is higher than the threshold, the computing device generates an exception alarm.
  • Step 7 If the number of exceptions is higher than the threshold or the available memory is lower than the threshold, the computing device generates a fault alarm.
  • the interface of the dynamic mirror memory provided by this embodiment is introduced below.
  • the interface of dynamic mirror memory includes data structure definition, user mode interface, kernel mode interface and so on.
  • API Application Programming Interface
  • a refined dynamic memory management development interface can be provided. The following describes the API provided by this embodiment from the data structure definition, the user-mode interface, and the kernel-mode interface.
  • vm_stat reference count new: NR_FREE_MIRROR_PAGES.
  • VM_MIRROR user mode
  • Non-programming interface task_struct->mirrorable, global variable mirrorable.
  • the new command mirrorable is used to modify the mirror configuration at runtime: /proc/pid/mirrorable.
  • Kernel mode interface (programming/non-programming)
  • dynamic memory mirroring in units of pages can be implemented.
  • FIG. 5 is a schematic structural diagram of a device for executing a memory read/write instruction provided by an embodiment of the present application.
  • the apparatus 500 shown in FIG. 5 for example, implements the functions of the computing device in the method shown in FIG. 3 .
  • the apparatus 500 includes a receiving unit 501 , a determining unit 502 and a reading and writing unit 503 .
  • Each unit in the apparatus 500 is implemented in whole or in part by software, hardware, firmware or any combination thereof.
  • the receiving unit 501 is configured to support the apparatus 500 to execute S301.
  • the determining unit 502 is configured to support the apparatus 500 to perform S302.
  • the read/write unit 503 is used to support the device 500 to execute S303.
  • the apparatus 500 further includes an allocation unit configured to support the apparatus 500 to perform the step of allocating memory space.
  • the read-write unit 503 is further configured to support the apparatus 500 to perform the steps of writing the mirroring indication information and modifying the mirroring flag of the specified object to a set value.
  • the apparatus 500 further includes an isolation unit configured to support the apparatus 500 to perform the step of isolating the faulty memory space.
  • the apparatus embodiment described in FIG. 5 is only schematic, for example, the division of the above-mentioned units is only a logical function division, and there may be other division methods in actual implementation, for example, multiple units or components may be combined or Integration into another system, or some features can be ignored, or not implemented.
  • Each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit.
  • the above-mentioned units in FIG. 5 can be implemented in the form of hardware, and can also be implemented in the form of software functional units.
  • the above determination unit 502 and read/write unit 503 may be implemented by software functional units generated after the processor 101 or the processor 105 in FIG.
  • the above units in FIG. 5 can also be implemented by different hardware in the computing device, for example, the determination unit 502 is determined by a part of the processing resources (for example, one core or two of the multi-core processors 101 in the at least one processor 101 in FIG. 1 ).
  • the read/write unit 503 is implemented by the rest of the processing resources in the processor 101 in FIG. 1 (such as other cores in the multi-core processor), or by using a field-programmable gate array (FPGA, FPGA). ), or programmable devices such as coprocessors.
  • the receiving unit 501 is realized by the network interface 103 in FIG. 1 .
  • the above-mentioned functional units can also be realized by a combination of software and hardware.
  • the determination unit 502 is realized by a hardware programmable device
  • the read-write unit 503 is a software functional unit generated after the CPU reads the program code stored in the memory. .
  • a computer program product includes one or more computer instructions.
  • the computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable device.
  • Computer instructions may be stored on or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server, or data center over a wire (e.g.
  • a computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, a data center, or the like that includes an integration of one or more available media.
  • Useful media may be magnetic media (eg, floppy disks, hard disks, magnetic tapes), optical media (eg, DVD), or semiconductor media (eg, Solid State Disk (SSD)), among others.

Abstract

The present application belongs to the field of computers. Provided are a method for executing a memory read-write instruction, and a computing device. According to the present application, in a page table entry corresponding to a virtual address, a field is enabled to carry mirror indication information, so as to indicate that mirror protection has been enabled for a memory space identified by the virtual address. When a memory read-write instruction is received, if it is discovered that there is mirror indication information in a page table entry corresponding to a virtual address that is carried in the memory read-write instruction, a read-write operation is performed on both two memory spaces corresponding to a master address and a standby address, such that a dynamic memory mirror function is supported, and the limitation of an existing memory mirror solution can be solved to a certain extent.

Description

内存读写指令的执行方法及计算设备Execution method and computing device of memory read and write instructions
本申请要求于2021年03月16日提交的申请号为202110281668.8、发明名称为“内存读写指令的执行方法及计算设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application with the application number 202110281668.8 filed on March 16, 2021 and the invention title is "Memory Read and Write Instruction Execution Method and Computing Device", the entire contents of which are incorporated into this application by reference .
技术领域technical field
本申请涉及计算机领域,特别涉及一种内存读写指令的执行方法及计算设备。The present application relates to the field of computers, and in particular, to a method for executing memory read and write instructions and a computing device.
背景技术Background technique
内存镜像(memory mirror)是一种内存保护技术。已启用内存镜像的内存空间包括主内存空间和镜像内存空间。主内存空间用于供内存控制器读取数据,镜像内存空间用于保存主内存空间中数据的备份。当主内存空间故障时,计算机能够从镜像内存空间恢复数据,从而提升内存稳定性和可用性。Memory mirroring is a memory protection technology. Memory mirroring-enabled memory spaces include main memory space and mirrored memory space. The main memory space is used for the memory controller to read data, and the mirror memory space is used to save the backup of the data in the main memory space. When the main memory space fails, the computer can recover data from the mirrored memory space, improving memory stability and availability.
时下,管理员会预先设定启用内存镜像的内存空间、镜像内存空间的尺寸以及基于内存镜像保护的软件模块等参数。计算机启动后,会固定通过预先设定的内存空间实现内存镜像。Nowadays, administrators pre-set parameters such as the memory space for enabling memory mirroring, the size of the mirrored memory space, and software modules based on memory mirroring protection. After the computer starts, it will implement memory mirroring through the preset memory space.
然而,上述方案中若预先设定的启用内存镜像的内存空间尺寸过小,容易导致对镜像内存的需求无法满足而导致内存溢出(out of memory,OOM),若预先设定的启用内存镜像的内存空间过大,会导致内存空间的浪费。由此可见,上述方案存在一定程度的局限性。However, if the preset memory size for enabling memory mirroring in the above solution is too small, the demand for mirrored memory may not be satisfied, resulting in out of memory (OOM). If the memory space is too large, it will lead to a waste of memory space. It can be seen that the above scheme has certain limitations.
发明内容SUMMARY OF THE INVENTION
本申请实施例提供了一种内存读写指令的执行方法及计算设备,有助于支持动态内存镜像的功能从而一定程度上解决现有内存镜像方案的局限性。所述技术方案如下。The embodiments of the present application provide a method and a computing device for executing a memory read and write instruction, which help to support the function of dynamic memory mirroring and thus solve the limitation of the existing memory mirroring scheme to a certain extent. The technical solution is as follows.
第一方面,提供了一种内存读写指令的执行方法,所述方法包括:接收内存读写指令,所述内存读写指令携带目标内存空间的虚拟地址;响应于所述虚拟地址对应的页表项包括镜像指示信息,根据所述虚拟地址确定主地址和镜像地址,所述镜像指示信息用于标识所述目标内存空间已启用内存镜像,所述主地址为所述目标内存空间中主内存空间的物理地址,所述镜像地址为所述目标内存空间中镜像内存空间的物理地址;根据所述主地址和所述镜像地址,对所述主内存空间和所述镜像内存空间执行所述内存读写指令对应的操作。A first aspect provides a method for executing a memory read/write instruction, the method comprising: receiving a memory read/write instruction, the memory read/write instruction carrying a virtual address of a target memory space; responding to a page corresponding to the virtual address The table entry includes mirroring indication information, the main address and mirroring address are determined according to the virtual address, the mirroring indication information is used to identify that memory mirroring has been enabled in the target memory space, and the main address is the main memory in the target memory space The physical address of the space, the mirror address is the physical address of the mirror memory space in the target memory space; according to the main address and the mirror address, execute the memory on the main memory space and the mirror memory space Operations corresponding to read and write instructions.
上述方法在虚拟地址对应的页表项中启用字段携带镜像指示信息,从而指明虚拟地址标识的内存空间已经启用了镜像保护。在收到内存读写指令时,如果发现内存读写指令携带的虚拟地址对应的页表项存在镜像指示信息,则主地址和备地址对应的两个内存空间均进行读写操作,从而支持了动态内存镜像功能,能够一定程度上解决现有内存镜像方案的局限性。The above method enables the field in the page table entry corresponding to the virtual address to carry the mirroring indication information, thereby indicating that mirroring protection has been enabled in the memory space identified by the virtual address. When a memory read/write command is received, if it is found that the page table entry corresponding to the virtual address carried by the memory read/write command has mirror indication information, the two memory spaces corresponding to the primary address and the standby address are both read and written, thus supporting The dynamic memory mirroring function can solve the limitations of the existing memory mirroring scheme to a certain extent.
可选地,所述镜像内存空间和所述主内存空间位于不同的通道。Optionally, the mirrored memory space and the main memory space are located in different channels.
通过这种方式,能够利用多个通道并行地对镜像内存空间和主内存空间,从而提升读写性能。In this way, multiple channels can be used to parallelize the mirrored memory space and the main memory space, thereby improving read and write performance.
可选地,所述镜像内存空间与所述主内存空间相隔至少一个缓存行尺寸的距离。Optionally, the mirrored memory space is separated from the main memory space by a distance of at least one cache line size.
通过这种方式,让地址计算的方式尽可能简便,降低实现复杂度。In this way, the address calculation method is made as simple as possible, and the implementation complexity is reduced.
可选地,所述主地址包括的偏移地址是根据缓存行尺寸以及所述虚拟地址包括的偏移地址确定的。Optionally, the offset address included in the main address is determined according to the size of the cache line and the offset address included in the virtual address.
通过这种方式,根据内存读写指令携带的虚拟地址以及缓存行尺寸即可确定主地址,计算复杂度低。In this way, the main address can be determined according to the virtual address carried by the memory read and write instructions and the size of the cache line, and the computational complexity is low.
可选地,所述根据所述主地址和所述镜像地址,对所述主内存空间和所述镜像内存空间执行所述内存读写指令对应的操作,包括:响应于所述主地址对应的ECC空间以及所述镜像地址对应的ECC空间均包括所述镜像指示信息,根据所述主地址和所述镜像地址,对所述主内存空间和所述镜像内存空间执行所述内存读写指令对应的操作。Optionally, performing an operation corresponding to the memory read/write instruction on the main memory space and the mirrored memory space according to the main address and the mirrored address includes: responding to the main memory corresponding to the main address. Both the ECC space and the ECC space corresponding to the mirror address include the mirror indication information, and according to the main address and the mirror address, execute the memory read and write instructions corresponding to the main memory space and the mirror memory space. operation.
通过这种方式,有助于避免非镜像内存空间被执行镜像读写操作,确保镜像保护的页只用于镜像读写操作。In this way, it helps to avoid mirrored read and write operations in non-mirrored memory space, and ensures that mirror-protected pages are only used for mirrored read and write operations.
可选地,所述接收内存读写指令之前,所述方法还包括:接收指定对象的内存分配请求;响应于所述指定对象的镜像标志置为设定值,为所述指定对象分配所述目标内存空间;其中,所述镜像标志在置为设定值时指示为指定对象分配包括主内存空间和镜像内存空间的内存空间。Optionally, before the receiving a memory read/write instruction, the method further includes: receiving a memory allocation request for a specified object; in response to setting a mirror flag of the specified object to a set value, allocating the specified object to the specified object. The target memory space; wherein, when the mirror flag is set to a set value, it indicates to allocate memory space including the main memory space and the mirror memory space for the specified object.
通过上述方式,针对指定对象运行时实际请求分配的内存采用镜像保护,避免预设过大的镜像内存导致内存资源浪费,同时避免预设的镜像内存不足导致业务中断。In the above manner, mirror protection is adopted for the memory actually requested to be allocated when the specified object is running, so as to avoid the waste of memory resources caused by the preset mirror memory that is too large, and avoid the service interruption caused by insufficient mirror memory.
可选地,所述接收指定对象的内存分配请求之后,所述方法还包括:向所述虚拟地址对应的页表项、所述主地址对应的ECC空间以及所述镜像地址对应的ECC空间分别写入所述镜像指示信息。Optionally, after receiving the memory allocation request for the specified object, the method further includes: sending the page table entry corresponding to the virtual address, the ECC space corresponding to the main address, and the ECC space corresponding to the mirror address, respectively. Write the mirroring indication information.
通过上述方式,将指定对象对应的页表项以及ECC空间中设置镜像指示信息,便于计算机各硬件识别指定对象的内存受到镜像保护。In the above manner, mirroring indication information is set in the page table entry corresponding to the specified object and the ECC space, so that each hardware of the computer can identify that the memory of the specified object is protected by mirroring.
可选地,所述接收指定对象的内存分配请求之前,所述方法还包括:响应于内存镜像指令,将所述指定对象的镜像标志修改为所述设定值,所述内存镜像指令指示针对所述指定对象所需的内存空间启用内存镜像。Optionally, before the receiving the memory allocation request of the specified object, the method further includes: in response to a memory mirroring instruction, modifying the mirroring flag of the specified object to the set value, the memory mirroring instruction indicating that The memory space required by the specified object enables memory mirroring.
通过上述方式,便于通过编程接口触发指令来定义对哪个对象启用镜像保护,便于满足自定义需求,提高灵活性。In the above manner, it is convenient to trigger an instruction through the programming interface to define which object to enable mirror protection, so as to meet the custom requirements and improve the flexibility.
可选地,所述虚拟地址标识的每一个虚拟页对应于两个相邻的物理页。Optionally, each virtual page identified by the virtual address corresponds to two adjacent physical pages.
可选地,所述方法还包括:响应于所述镜像内存空间发生故障,隔离所述镜像内存空间;为所述虚拟地址重新分配镜像内存空间,将所述主内存空间保存的数据写入至重新分配的镜像内存空间。Optionally, the method further includes: in response to a failure of the mirrored memory space, isolating the mirrored memory space; reallocating the mirrored memory space for the virtual address, and writing the data stored in the main memory space to a Reallocated mirrored memory space.
通过上述方式,从而降低内存故障对系统的影响,提高可靠性。In the above manner, the influence of the memory failure on the system is reduced, and the reliability is improved.
第二方面,提供了一种内存读写指令的执行装置,该装置具有实现上述第一方面或第一方面任一种可选方式的功能。该装置包括至少一个单元,至少一个单元用于实现上述第一方面或第一方面任一种可选方式所提供的方法。在一些实施例中,该装置中的单元通过软件实现,装置中的单元是程序模块。在另一些实施例中,该装置中的单元通过硬件或固件实现。第二方面提供的装置的具体细节可参见上述第一方面或第一方面任一种可选方式,此处不再赘述。In a second aspect, a device for executing memory read and write instructions is provided, and the device has the function of implementing the first aspect or any optional manner of the first aspect. The apparatus includes at least one unit, and the at least one unit is configured to implement the method provided in the first aspect or any optional manner of the first aspect. In some embodiments, the elements in the apparatus are implemented in software, and the elements in the apparatus are program modules. In other embodiments, the units in the apparatus are implemented by hardware or firmware. For specific details of the apparatus provided in the second aspect, reference may be made to the foregoing first aspect or any optional manner of the first aspect, which will not be repeated here.
第三方面,提供了一种计算设备,该计算设备包括处理器和存储器,所述存储器中存储有至少一条程序代码,所述程序代码由所述处理器加载并执行以实现上述第一方面或第一方面任一种可选方式所提供的方法。In a third aspect, a computing device is provided, the computing device includes a processor and a memory, the memory stores at least one piece of program code, the program code is loaded and executed by the processor to implement the above-mentioned first aspect or The method provided in any optional manner of the first aspect.
第四方面,提供了一种计算机可读存储介质,该存储介质中存储有至少一条指令,该指令在计算机上运行时,使得计算机执行上述第一方面或第一方面任一种可选方式所提供的方法。A fourth aspect provides a computer-readable storage medium, where at least one instruction is stored in the storage medium, and when the instruction is executed on a computer, causes the computer to execute the above-mentioned first aspect or any optional manner of the first aspect. provided method.
第五方面,提供了一种计算机程序产品,所述计算机程序产品包括一个或多个计算机程序指令,当所述计算机程序指令被计算机加载并运行时,使得所述计算机执行上述第一方面或第一方面任一种可选方式所提供的方法。In a fifth aspect, a computer program product is provided, the computer program product includes one or more computer program instructions, when the computer program instructions are loaded and executed by a computer, cause the computer to execute the first aspect or the first aspect above. A method provided by any of the alternatives on the one hand.
第六方面,提供了一种芯片,包括存储器和处理器,存储器用于存储计算机指令,处理器用于从存储器中调用并运行该计算机指令,以执行上述第一方面及其第一方面任意可能的实现方式中的方法。In a sixth aspect, a chip is provided, including a memory and a processor, the memory is used to store computer instructions, and the processor is used to call and run the computer instructions from the memory to execute the above-mentioned first aspect and any possible possible aspects of the first aspect. method in the implementation.
第七方面,提供了一种计算设备,所述计算设备包括内存管理单元(memory management unit,MMU)、内存控制器(memory controller,MC)和内存;所述MMU,用于接收内存读写指令,所述内存读写指令携带目标内存空间的虚拟地址;所述MMU,还用于响应于所述虚拟地址对应的页表项包括镜像指示信息,根据所述虚拟地址确定主地址和镜像地址,所述镜像指示信息用于标识所述目标内存空间已启用内存镜像,所述主地址为所述目标内存空间中主内存空间的物理地址,所述镜像地址为所述目标内存空间中镜像内存空间的物理地址;所述MC用于根据所述主地址和所述镜像地址,对所述内存中的主内存空间和所述内存中的镜像内存空间执行所述内存读写指令对应的操作。A seventh aspect, a computing device is provided, the computing device includes a memory management unit (memory management unit, MMU), a memory controller (memory controller, MC) and a memory; the MMU is used for receiving memory read and write instructions , the memory read-write instruction carries the virtual address of the target memory space; the MMU is further configured to determine the main address and the mirror address according to the virtual address in response to the page table entry corresponding to the virtual address including the mirroring indication information, The mirroring indication information is used to identify that memory mirroring has been enabled in the target memory space, the main address is the physical address of the main memory space in the target memory space, and the mirroring address is the mirrored memory space in the target memory space The physical address of the MC; the MC is configured to perform operations corresponding to the memory read and write instructions on the main memory space in the memory and the mirror memory space in the memory according to the main address and the mirror address.
附图说明Description of drawings
图1是本申请实施例提供的一种计算设备的结构示意图;FIG. 1 is a schematic structural diagram of a computing device provided by an embodiment of the present application;
图2是本申请实施例提供的一种读写内存的示意图;2 is a schematic diagram of a read-write memory provided by an embodiment of the present application;
图3是本申请实施例提供的一种内存读写指令的执行方法的流程图;3 is a flowchart of a method for executing a memory read/write instruction provided by an embodiment of the present application;
图4是本申请实施例提供的一种主地址与镜像地址之间关系的示意图;4 is a schematic diagram of a relationship between a primary address and a mirror address provided by an embodiment of the present application;
图5是本申请实施例提供的一种内存读写指令的执行装置的结构示意图。FIG. 5 is a schematic structural diagram of a device for executing a memory read/write instruction provided by an embodiment of the present application.
具体实施方式Detailed ways
为使本申请的目的、技术方案和优点更加清楚,下面将结合附图对本申请实施方式作进一步地详细描述。In order to make the objectives, technical solutions and advantages of the present application clearer, the embodiments of the present application will be further described in detail below with reference to the accompanying drawings.
下面对本申请实施例涉及的一些术语概念做解释说明。Some terms and concepts involved in the embodiments of the present application are explained below.
(1)通道(channel)(1) channel (channel)
通道是指内存控制器与存储介质之间的物理通路。内存控制器与存储介质之间可选地具有一个或多个通道。不同通道之间可以串行工作,也可以并行工作。在多个通道并行工作的情况下,能提高内存的带宽和吞吐量。A channel refers to the physical path between the memory controller and the storage medium. There is optionally one or more channels between the memory controller and the storage medium. Different channels can work serially or in parallel. In the case of multiple channels working in parallel, it can improve the bandwidth and throughput of the memory.
(2)内存地址交织(channel interleave或interleaved memory)(2) Memory address interleaving (channel interleave or interleaved memory)
内存地址交织是指将内存地址均匀分布在一组通道的编址方式。例如,存在2个通道,分别是通道0和通道1,在启用内存地址交织的情况下,如果虚拟地址32属于通道0,那么虚拟地址33属于通道1,虚拟地址34属于通道0,虚拟地址35属于通道1,以此类推。通过启用内存地址交织,能够并行或者轮流使用每个通道进行连续的内存读写,从而减少内存 读写的耗时,提高内存读写的效率。Memory address interleaving refers to an addressing method that evenly distributes memory addresses across a group of channels. For example, there are 2 channels, channel 0 and channel 1. With memory address interleaving enabled, if virtual address 32 belongs to channel 0, then virtual address 33 belongs to channel 1, virtual address 34 belongs to channel 0, and virtual address 35 belongs to channel 1, and so on. By enabling memory address interleaving, each channel can be used in parallel or in turn to perform continuous memory reading and writing, thereby reducing the time consuming of memory reading and writing and improving the efficiency of memory reading and writing.
(3)启用内存镜像的内存空间(3) Enable memory space for memory mirroring
启用内存镜像的内存空间包括两个独立的物理内存空间。一个物理内存空间充当主内存空间,另外一个物理内存空间充当镜像内存空间。当进程、内核或者其他对象发起对启用内存镜像的内存空间的写数据指令时,数据会同时写入至主内存空间和镜像内存空间,使得数据在内存中存在相同的两份。通常情况下,主内存空间用于进行读写,而镜像内存空间用于保存数据的备份。如果主内存空间出现故障,可从镜像内存空间恢复内存数据。通常情况下,镜像内存空间的容量和主内存空间的容量相同。例如,主内存空间的容量是N个页,镜像内存空间的容量也是N个页。A memory space with memory mirroring enabled consists of two separate physical memory spaces. One physical memory space acts as the main memory space, and the other physical memory space acts as the mirror memory space. When a process, kernel, or other object initiates a write data command to a memory space with memory mirroring enabled, the data will be written to the main memory space and the mirrored memory space at the same time, so that the same two copies of the data exist in memory. Typically, the main memory space is used for reading and writing, while the mirror memory space is used to hold backups of data. If the main memory space fails, memory data can be recovered from the mirrored memory space. Typically, the mirrored memory space has the same capacity as the main memory space. For example, the capacity of the main memory space is N pages, and the capacity of the mirror memory space is also N pages.
(4)镜像指示信息(镜像indicator)(4) Mirror indication information (mirror indicator)
镜像指示信息是本实施例提供的用于标识是否启用内存镜像的指示信息。通过镜像指示信息,能够区分要访问的内存空间是启用内存镜像的内存空间还是没有启用内存镜像的内存空间。具体来说,在内存分配流程中,如果分配的内存空间A是启用内存镜像的内存空间,则为内存空间A标记对应的镜像指示信息;在内存读写流程中,当内存管理单元(memory management unit,MMU)检测到镜像指示信息时,MMU会按照本实施例提供的地址计算方式计算主内存空间的物理地址,当内存控制器(memory controller,MC)检测到镜像指示信息时,MC会按照本实施例提供的地址计算方式计算镜像内存空间的物理地址,从而将虚拟地址正确转换为主内存空间的物理地址和镜像内存空间的物理地址。可选地,镜像指示信息占用预留字段中的一个比特位。镜像指示信息占用的一个比特位可称为镜像指示信息字段,该比特位置位(即值为1)表示具有镜像指示信息,该比特位没有置位(即值为0)表示不具有镜像指示信息。The mirroring indication information is the indication information provided by this embodiment for identifying whether to enable memory mirroring. Through the mirroring indication information, it is possible to distinguish whether the memory space to be accessed is a memory space with memory mirroring enabled or a memory space without memory mirroring enabled. Specifically, in the memory allocation process, if the allocated memory space A is a memory space with memory mirroring enabled, the corresponding mirroring indication information is marked for the memory space A; in the memory read-write process, when the memory management unit (memory management unit) unit, MMU) detects the mirroring indication information, the MMU will calculate the physical address of the main memory space according to the address calculation method provided in this embodiment, and when the memory controller (memory controller, MC) detects the mirroring indication information, the MC will follow the The address calculation method provided in this embodiment calculates the physical address of the mirrored memory space, so as to correctly convert the virtual address to the physical address of the main memory space and the physical address of the mirrored memory space. Optionally, the mirroring indication information occupies one bit in the reserved field. A bit occupied by the mirroring indication information can be called the mirroring indication information field. If the bit position is set (that is, the value is 1), it indicates that the mirroring indication information is available. If the bit is not set (that is, the value is 0), it indicates that the mirroring indication information is not available. .
(5)镜像标志(镜像flag)(5) Mirror flag (mirror flag)
镜像标志是本实施例提供的用于标识是否分配启用内存镜像的内存空间的标志。例如,当镜像标志置为设定值(如1)时,表示分配包括启用内存镜像的内存空间。当镜像标志未置为设定值时,表示仅分配请求所指定大小的内存空间。例如,进程A发送内存分配请求,该内存分配请求指示为进程A分配一个页的内存空间。如果进程A的镜像标志为1,则为进程A分配两个物理页,一个物理页是主内存空间,另一个物理页是镜像内存空间。如果进程A的镜像标志为0,则为进程A分配一个物理页。The mirroring flag is a flag provided in this embodiment for identifying whether to allocate a memory space for enabling memory mirroring. For example, when the mirroring flag is set to a set value (such as 1), it indicates that the allocation of memory space includes enabling memory mirroring. When the mirror flag is not set to the set value, it means that only the memory space of the size specified by the request is allocated. For example, process A sends a memory allocation request indicating that process A is allocated a page of memory space. If the mirror flag of process A is 1, two physical pages are allocated for process A, one physical page is the main memory space, and the other physical page is the mirror memory space. If process A's mirroring flag is 0, process A is allocated a physical page.
镜像标志例如是内存分配函数的一个输入参数。镜像标志指示执行内存分配函数时分配启用内存镜像的内存空间。例如,内存分配函数是kmalloc函数,镜像标志是kmalloc函数的一种获取空闲页(get free pages,GFP)分配标志(也称内存分配标志或flags参数)。又如,内存分配函数是vmalloc函数,镜像标志是vmalloc函数中的一种虚拟地址空间(virtual memory area,VMA)标志。The mirror flag is, for example, an input parameter of a memory allocation function. The mirroring flag instructs memory space to be allocated with memory mirroring enabled when the memory allocation function is executed. For example, the memory allocation function is the kmalloc function, and the mirror flag is a get free page (get free pages, GFP) allocation flag (also called the memory allocation flag or the flags parameter) of the kmalloc function. For another example, the memory allocation function is the vmalloc function, and the image flag is a virtual address space (virtual memory area, VMA) flag in the vmalloc function.
(6)缓存行(cache line)(6) cache line (cache line)
缓存是对内存的内容进行缓存的硬件。缓存行是缓存的基本单位。缓存行尺寸(cache line size)是指一个缓存行的尺寸。计算机在访问内存时,会按照缓存行尺寸为单位,将内存中的数据迁移到缓存中。例如,缓存行尺寸是N个字节,计算机在访问内存时,一次最少迁移内存中N个字节的数据到缓存中。A cache is hardware that caches the contents of memory. A cache line is the basic unit of a cache. Cache line size refers to the size of a cache line. When the computer accesses the memory, it will migrate the data in the memory to the cache according to the size of the cache line. For example, the cache line size is N bytes, and when the computer accesses the memory, at least N bytes of data in the memory are migrated to the cache at a time.
(7)错误检查和纠正(Error Correcting Code,ECC)空间(7) Error checking and correction (Error Correcting Code, ECC) space
ECC空间是指内存中保存ECC技术中校验和的区域。ECC是一种指令纠错技术。ECC的基本原理是,每一次数据写入内存的时候,ECC码使用一种特殊的算法对数据进行计算,其结果称为校验位(check bits)。然后将所有校验位加在一起得到校验和(checksum),校验和与数据一起存放在内存中。当数据从内存中读出时,采用同一算法再次计算校验和,并和前面的计算结果相比较,如果结果相同,说明数据是正确的,反之说明有错误,则从逻辑上分离错误并通知系统。当只出现单比特错误的时候,ECC可以把错误改正过来不影响系统运行。ECC space refers to the area in memory where checksums in ECC technology are kept. ECC is an instruction error correction technique. The basic principle of ECC is that each time data is written into the memory, the ECC code uses a special algorithm to calculate the data, and the result is called check bits. Then add all the check bits together to get the checksum (checksum), and the checksum is stored in memory along with the data. When the data is read from the memory, the same algorithm is used to calculate the checksum again and compare it with the previous calculation result. If the result is the same, it means that the data is correct, otherwise it means that there is an error, then the error is logically separated and notified. system. When only a single-bit error occurs, ECC can correct the error without affecting system operation.
内存故障轻者导致应用进程异常终止或崩溃,部分业务中断;严重时操作系统(operation system,OS)宕机,全部业务中断。目前,除了采用内存ECC等可靠性、可用性和诊断(Reliability,Availability and Serviceability,RAS)技术来进行故障检测、纠错外,关键业务(Mission Critical)还需要内存镜像技术进一步降低内存故障导致业务中断的可能性。在启动内存镜像的情况下,内存空间按照主内存空间、镜像内存空间的方式组织,并以一个主内存空间和一个镜像内存空间为单位分配给应用。当主内存空间、镜像内存空间中一个内存空间故障时,系统可以从另外一个内存空间恢复数据,从而避免应用或系统宕机。If the memory failure is mild, the application process will be terminated or crashed abnormally, and some services will be interrupted. In severe cases, the operating system (OS) will be down, and all services will be interrupted. At present, in addition to using memory ECC and other reliability, availability and diagnostic (Reliability, Availability and Serviceability, RAS) technologies for fault detection and error correction, mission critical also requires memory mirroring technology to further reduce memory failures and business interruptions possibility. In the case of enabling memory mirroring, the memory space is organized in the manner of the main memory space and the mirrored memory space, and is allocated to the application in units of a main memory space and a mirrored memory space. When one memory space in the main memory space and the mirrored memory space fails, the system can restore data from another memory space, thereby avoiding application or system downtime.
然而,目前内存镜像技术的成本较高,而且当预先设定的镜像内存空间不足时仍然会OOM,导致业务中断。修改镜像空间必须重新启动(reboot)才能生效,也会中断业务。一些研究尝试使用全镜像模式(full mirror mode)、部分镜像模式(partial mirror mode)、地址范围镜像模式(address range mirroring)等方式实现内存镜像。然而,这几种模式下内存镜像关系是固定的,无法满足软件对关键业务内存模块的动态镜像管理需求。具体地,当预设的镜像内存不能满足内核需要会OOM,预设镜像过大又导致内存浪费;并且,需要OS支持才能完全利用地址范围镜像;并且,需要提供固件-OS(Firmware-OS)接口,OS必须与基本输入输出系统(Basic Input Output System,BIOS)交互确定镜像区域(region)信息;并且,修改镜像区域尺寸(region size)必须重启操作系统才能生效;并且,应用进程不能获得镜像保护。However, the cost of the current memory mirroring technology is relatively high, and when the preset mirror memory space is insufficient, OOM will still occur, resulting in service interruption. Modifying the mirror space must be restarted (reboot) to take effect, and will also interrupt services. Some researches try to implement memory mirroring using full mirror mode, partial mirror mode, address range mirroring, etc. However, the memory mirroring relationship in these modes is fixed, which cannot meet the software's dynamic mirroring management requirements for key business memory modules. Specifically, when the preset image memory cannot meet the needs of the kernel, OOM occurs, and the preset image is too large, which leads to a waste of memory; moreover, OS support is required to fully utilize the address range image; and, firmware-OS (Firmware-OS) needs to be provided. interface, the OS must interact with the Basic Input Output System (BIOS) to determine the mirror region information; and, to modify the mirror region size (region size), the operating system must be restarted to take effect; and the application process cannot obtain the mirror image Protect.
有鉴于此,本申请实施例提供了一种动态内存镜像方案,仅对OS或关键业务进程实际分配的内存采取镜像保护,在确保内存故障不会导致中断业务的条件下,既能避免预设过大的镜像内存导致昂贵内存资源的浪费,也能避免预设内存镜像空间不足导致镜像保护失效或OOM导致业务中断的严重后果。此外,现有镜像方案也不能解决镜像内存故障后再分配新的镜像空间的问题,导致业务连续性得不到很好保证;而本申请实施例在动态镜像内存故障时,系统可以另外分配新的镜像内存并隔离故障内存,从而保证业务的连续性。In view of this, the embodiment of the present application provides a dynamic memory mirroring scheme, which only adopts mirror protection for the memory actually allocated by the OS or key business processes, and can avoid the preset memory under the condition that the memory failure will not lead to interruption of the business. Excessive mirroring memory leads to waste of expensive memory resources, and it can also avoid the serious consequences of insufficient mirroring space in the preset memory, failure of mirroring protection, or service interruption caused by OOM. In addition, the existing mirroring solution cannot solve the problem of allocating new mirroring space after the mirroring memory fails, resulting in that the business continuity cannot be well guaranteed; while in the embodiment of the present application, when the dynamic mirroring memory fails, the system can additionally allocate a new mirroring space. Mirror memory and isolate faulty memory to ensure business continuity.
下面对本申请实施例涉及的计算设备的基本硬件结构举例说明。The basic hardware structure of the computing device involved in the embodiments of the present application is illustrated below with an example.
附图1是本申请实施例提供的一种计算设备的结构示意图。附图1所示的计算设备100用于执行本申请实施例提供的方法。FIG. 1 is a schematic structural diagram of a computing device provided by an embodiment of the present application. The computing device 100 shown in FIG. 1 is used to execute the method provided by the embodiment of the present application.
计算设备100包括处理器101、存储器102以及网络接口103。 Computing device 100 includes processor 101 , memory 102 , and network interface 103 .
处理器101包括CPU、MMU以及MC。CPU包括CPU执行单元以及MMU。The processor 101 includes a CPU, an MMU, and an MC. The CPU includes a CPU execution unit and an MMU.
CPU执行单元是指CPU中处理数据或计算机程序指令的硬件单元,例如,CPU执行单元是一个或多个CPU核。在执行镜像内存读写的流程中,CPU执行单元用于生成和发送内存读写指令。A CPU execution unit refers to a hardware unit in a CPU that processes data or computer program instructions. For example, a CPU execution unit is one or more CPU cores. In the process of executing mirrored memory read and write, the CPU execution unit is used to generate and send memory read and write instructions.
MMU用于将虚拟地址转换为物理地址。具体地,如附图2所示,CPU执行单元发送内存读写指令后,MMU截获内存读写指令,执行地址转换,即将内存读写指令中的虚拟地址转换为物理地址。之后,MMU将地址转换后的指令发送给MC。MMU地址转换的动作也称为翻译。MMU使用页表来实现虚拟地址到物理地址的转换。在本申请实施例中,MMU地址转换得到的物理地址包括主地址或镜像地址中的至少一项。例如,在一些实施例中,如附图2所示,MMU将主地址和镜像地址发送给MC;MC接收MMU发送的主地址和镜像地址,根据主地址和镜像地址对内存执行镜像读写操作。在另一些实施例中,MMU将主地址和虚拟地址发送给MC,MC接收MMU发送的主地址和虚拟地址,MC根据主地址和虚拟地址确定镜像地址。之后,MC根据主地址和镜像地址对内存执行镜像读写操作。MMU通常设置在CPU内部。The MMU is used to translate virtual addresses to physical addresses. Specifically, as shown in FIG. 2 , after the CPU execution unit sends the memory read and write instructions, the MMU intercepts the memory read and write instructions, and performs address conversion, that is, converts the virtual addresses in the memory read and write instructions into physical addresses. After that, the MMU sends the address-translated instruction to the MC. The action of MMU address translation is also called translation. The MMU uses page tables to implement virtual to physical address translation. In this embodiment of the present application, the physical address obtained by the MMU address conversion includes at least one of a main address or a mirror address. For example, in some embodiments, as shown in FIG. 2, the MMU sends the main address and the mirror address to the MC; the MC receives the main address and the mirror address sent by the MMU, and performs mirror read and write operations on the memory according to the main address and the mirror address . In other embodiments, the MMU sends the main address and the virtual address to the MC, the MC receives the main address and the virtual address sent by the MMU, and the MC determines the mirror address according to the main address and the virtual address. After that, the MC performs mirrored read and write operations on the memory according to the main address and the mirrored address. The MMU is usually set up inside the CPU.
页表存储在内存中,页表中的每一行对应于虚拟存储空间的一个页,该行包含了该虚拟内存页对应的物理内存页的地址、该页的访问权限和该页的缓冲特性等。页表中的每一个条目称为一个页表项。The page table is stored in memory. Each row in the page table corresponds to a page in the virtual storage space. The row contains the address of the physical memory page corresponding to the virtual memory page, the access authority of the page, and the buffering characteristics of the page. . Each entry in the page table is called a page table entry.
MC用于控制内存,通过MC实现内存与CPU之间的数据交换。具体地,MC用于根据MMU发来的指令携带的物理地址访问内存。在读数据的情况下,MC从内存中物理地址对应的位置获取数据,将数据返回给CPU。在写数据的情况下,MC将数据写入至物理地址对应的位置。当MC接收到MMU发送的内存读写指令时,MC判断内存读写指令是否是镜像读写指令,并判断ECC中镜像指示信息字段是否置位;如果内存读写指令是镜像读写指令且ECC中镜像指示信息字段置位,则MC执行镜像读写操作,即对主内存空间和镜像内存空间同时执行读数据操作或者写数据操作。如果内存读写指令不是镜像读写指令且ECC中镜像指示信息字段置位,则MC拒绝执行内存读写指令,从而避免镜像内存被非法访问。The MC is used to control the memory, and the data exchange between the memory and the CPU is realized through the MC. Specifically, the MC is used to access the memory according to the physical address carried by the instruction sent by the MMU. In the case of reading data, the MC obtains the data from the location corresponding to the physical address in the memory, and returns the data to the CPU. In the case of writing data, the MC writes the data to the location corresponding to the physical address. When the MC receives the memory read/write command sent by the MMU, the MC judges whether the memory read/write command is a mirror read/write command, and judges whether the mirror indication information field in the ECC is set; if the memory read/write command is a mirror read/write command and the ECC If the medium mirror indication information field is set, the MC performs mirror read and write operations, that is, perform read data operations or write data operations on the main memory space and the mirror memory space at the same time. If the memory read/write command is not a mirror read/write command and the mirroring indication information field in the ECC is set, the MC refuses to execute the memory read/write command, thereby preventing the mirrored memory from being illegally accessed.
MC与CPU之间的位置关系包括多种情况。可选地,MC设置在CPU内部,也即是,MC与CPU集成在一起。或者,MC设置在CPU外部,也即是,MC与CPU分离设置。例如,附图2中处理器101中的MC设置在CPU内部,处理器105中的MC设置在CPU外部。The positional relationship between the MC and the CPU includes various cases. Optionally, the MC is provided inside the CPU, that is, the MC is integrated with the CPU. Alternatively, the MC is provided outside the CPU, that is, the MC is provided separately from the CPU. For example, in FIG. 2, the MC in the processor 101 is arranged inside the CPU, and the MC in the processor 105 is arranged outside the CPU.
存储器102包括内存。内存包括ECC空间。存储器102例如是只读存储器(read-only memory,ROM)或可存储静态信息和指令的其它类型的静态存储设备,又如是随机存取存储器(random access memory,RAM)或者可存储信息和指令的其它类型的动态存储设备,又如是电可擦可编程只读存储器(electrically erasable programmable read-only Memory,EEPROM)、只读光盘(compact disc read-only memory,CD-ROM)或其它光盘存储、光碟存储(包括压缩光碟、激光碟、光碟、数字通用光碟、蓝光光碟等)、磁盘存储介质或者其它磁存储设备,或者是能够用于携带或存储具有指令或数据结构形式的期望的程序代码并能够由计算机存取的任何其它介质,但不限于此。The memory 102 includes memory. Memory includes ECC space. The memory 102 is, for example, a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, or a random access memory (RAM) or a device that can store information and instructions. Other types of dynamic storage devices, such as electrically erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disk storage, optical disks storage (including compact discs, laser discs, compact discs, digital versatile discs, Blu-ray discs, etc.), magnetic disk storage media, or other magnetic storage devices, or capable of carrying or storing desired program code in the form of instructions or data structures and capable of Any other medium accessed by a computer without limitation.
在一些实施例中,计算设备100还包括总线104。可选地,总线104是内存总线或者系统总线。处理器101、存储器102以及网络接口103通过总线104连接。总线104用于在上述组件之间传送信息。In some embodiments, computing device 100 also includes bus 104 . Optionally, bus 104 is a memory bus or a system bus. The processor 101 , the memory 102 and the network interface 103 are connected through a bus 104 . The bus 104 is used to transfer information between the aforementioned components.
在一些实施例中,计算设备100还包括输入输出接口106。输入输出接口106连接到总线104上。In some embodiments, computing device 100 also includes an input-output interface 106 . An input-output interface 106 is connected to the bus 104 .
在一些实施例中,输入输出接口106用于与输入设备连接,接收用户通过输入设备输入的下述方法实施例涉及的命令或数据,例如内存镜像指令。输入设备包括但不限于键盘、触 摸屏、麦克风、鼠标或传感设备等等。In some embodiments, the input-output interface 106 is used for connecting with an input device, and receiving commands or data involved in the following method embodiments input by a user through the input device, such as memory mirroring instructions. Input devices include, but are not limited to, keyboards, touch screens, microphones, mice, or sensing devices, among others.
在一些实施例中,输入输出接口106还用于与输出设备连接。输入输出接口106通过输出设备输出处理器301执行下述方法实施例产生的中间结果和/或最终结果,例如从内存中读取的数据。输出设备包括但不限于显示器、打印机、投影仪等等。In some embodiments, the input-output interface 106 is also used to interface with output devices. The input-output interface 106 outputs the intermediate results and/or final results generated by the processor 301 by executing the following method embodiments, such as data read from the memory, through the output device. Output devices include, but are not limited to, displays, printers, projectors, and the like.
可选地,处理器101通过读取存储器102中保存的程序代码实现上述实施例中的方法,或者,处理器101通过内部存储的程序代码实现上述实施例中的方法。在处理器101通过读取存储器102中保存的程序代码实现上述实施例中的方法的情况下,存储器102中保存实现本申请实施例提供的方法的程序代码。Optionally, the processor 101 implements the methods in the above embodiments by reading program codes stored in the memory 102, or the processor 101 implements the methods in the above embodiments by using internally stored program codes. When the processor 101 implements the method in the above embodiment by reading the program code stored in the memory 102, the memory 102 stores the program code for implementing the method provided by the embodiment of the present application.
处理器101实现上述功能的更多细节请参考前面各个方法实施例中的描述,在这里不再重复。For more details of the above-mentioned functions implemented by the processor 101, please refer to the descriptions in the foregoing method embodiments, which will not be repeated here.
下面对本申请实施例的方法流程举例说明。The method flow of the embodiment of the present application is illustrated below with an example.
附图3是本申请实施例提供的一种内存读写指令的执行方法的流程图。附图3所示方法包括以下步骤S301至步骤S303。FIG. 3 is a flowchart of a method for executing a memory read/write instruction provided by an embodiment of the present application. The method shown in FIG. 3 includes the following steps S301 to S303.
步骤S301、计算设备接收内存读写指令。Step S301, the computing device receives a memory read and write instruction.
内存读写指令用于指示对目标内存空间进行读数据操作或者写数据操作。目标内存空间是指计算设备的内存中当前需要访问的空间。内存读写指令携带目标内存空间的虚拟地址。例如,内存读写指令包括目的地址字段,目的地址字段的内容包括目标内存空间的虚拟地址。The memory read and write instructions are used to instruct a data read operation or a write data operation to the target memory space. The target memory space refers to the space that needs to be accessed currently in the memory of the computing device. Memory read and write instructions carry the virtual address of the target memory space. For example, a memory read/write instruction includes a destination address field, and the content of the destination address field includes a virtual address of the target memory space.
目标内存空间的虚拟地址包括基地址和偏移地址。虚拟地址中的基地址也称页号,用于标识对应的虚拟页。虚拟地址中的偏移地址也称页偏移,用于标识虚拟页内部的位置。其中,虚拟页也称逻辑页,是与物理页相对的概念。The virtual address of the target memory space includes the base address and the offset address. The base address in the virtual address, also called the page number, is used to identify the corresponding virtual page. The offset address in the virtual address, also called the page offset, is used to identify the location inside the virtual page. Among them, a virtual page is also called a logical page, which is a concept relative to a physical page.
步骤S302、响应于虚拟地址对应的页表项(page table entry,PTE)包括镜像指示信息,计算设备根据虚拟地址确定主地址和镜像地址。Step S302, in response to the page table entry (page table entry, PTE) corresponding to the virtual address including the mirroring indication information, the computing device determines the main address and the mirroring address according to the virtual address.
页表用于记录虚拟地址对应的物理地址,此外页表还包括预留(reserved)字段。The page table is used to record the physical address corresponding to the virtual address, and the page table also includes a reserved field.
镜像指示信息用于标识目标内存空间已启用内存镜像。页表项中的镜像指示信息位于页表项的预留字段。例如,在页表项的预留字段中启用一个或多个比特位作为镜像指示信息字段。若页表项中的镜像指示信息字段置位(即页表项包括镜像指示信息),表示目标内存空间已启用内存镜像。若页表项中的镜像指示信息字段没有置位(即页表项不包括镜像指示信息),表示目标内存空间没有启用内存镜像。例如,ARM架构的PTE包括上层属性(upper attributes)字段、输出块地址(output block address)字段以及底层属性(lower attributes)字段,上层属性字段包括供软件使用的保留(reserved for software use)字段,启用供软件使用的保留字段中的一个比特作为镜像指示信息字段。The mirroring indication is used to identify that the target memory space has memory mirroring enabled. The mirroring indication information in the page table entry is located in the reserved field of the page table entry. For example, one or more bits are enabled in the reserved field of the page table entry as the mirror indication information field. If the mirroring indication information field in the page table entry is set (that is, the page table entry includes mirroring indication information), it means that memory mirroring is enabled in the target memory space. If the mirroring indication information field in the page table entry is not set (that is, the page table entry does not include mirroring indication information), it means that memory mirroring is not enabled in the target memory space. For example, the PTE of the ARM architecture includes an upper attribute field, an output block address field, and a lower attribute field, and the upper attribute field includes a reserved for software use field, A bit in a field reserved for software use is enabled as a mirror indication field.
通过在页表项中启用字段携带镜像指示信息,MMU通过页表项是否携带镜像指示信息能识别虚拟地址是否启用动态镜像,从而解决MMU不支持把虚拟地址翻译成真正的镜像地址的问题。By enabling the field in the page table entry to carry the mirroring indication information, the MMU can identify whether dynamic mirroring is enabled for the virtual address through whether the page table entry carries the mirroring indication information, thereby solving the problem that the MMU does not support translating virtual addresses into real mirroring addresses.
主地址为目标内存空间中主内存空间的物理地址(Physical Address,PA)。主地址包括基地址以及偏移地址。基地址相当于物理页的页号。例如,参见附图4,附图4中以“Pri+数字”的形式来简化表示具体的主地址,例如附图4中Pri0、Pri1……Pri4095中的每一个均表示具体的主地址。其中,Pri是“Primary(主,指代主内存空间)”的缩写。The main address is the physical address (Physical Address, PA) of the main memory space in the target memory space. The main address includes the base address and the offset address. The base address corresponds to the page number of the physical page. For example, referring to FIG. 4, a specific main address is simplified in the form of “Pri+number” in FIG. 4, for example, each of Pri0, Pri1...Pri4095 in FIG. 4 represents a specific main address. Among them, Pri is the abbreviation of "Primary (main, referring to the main memory space)".
镜像地址为目标内存空间中镜像内存空间的物理地址。镜像地址包括基地址以及偏移地址。例如,参见附图4,附图4中以“Sec+数字”的形式来简化表示具体的镜像地址,例如附图4中Sec0、Sec1……Sec4095中的每一个均表示具体的镜像地址。其中,Sec是“Secondary(备,指代镜像内存空间)”的缩写。The mirror address is the physical address of the mirror memory space in the target memory space. The mirror address includes the base address and the offset address. For example, referring to FIG. 4 , a specific mirror address is simplified in the form of “Sec+number” in FIG. 4 . For example, each of Sec0 , Sec1 . . . Sec4095 in FIG. 4 represents a specific mirror address. Among them, Sec is the abbreviation of "Secondary (standby, referring to the mirrored memory space)".
在一些实施例中,镜像内存空间与主内存空间相隔一个或多个缓存行尺寸的距离。可选地,镜像内存空间与主内存空间相隔一个缓存行尺寸的距离。In some embodiments, the mirrored memory space is separated from the main memory space by a distance of one or more cache line sizes. Optionally, the mirrored memory space is separated from the main memory space by a distance of one cache line size.
在一些实施例中,主地址与镜像地址相隔至少一个缓存行尺寸的距离。可选地,主地址与镜像地址相隔一个缓存行尺寸的距离。例如,参见附图4,主地址Pri0和备地址Sec0具有镜像关系,主地址Pri63和备地址Sec63具有镜像关系,主地址Pri0和备地址Sec0相隔一个缓存行尺寸的距离,主地址Pri63和备地址Sec63相隔一个缓存行尺寸的距离。通过这种方式,让地址计算的方式尽可能简便,降低实现复杂度。In some embodiments, the primary address is separated from the mirrored address by a distance of at least one cache line size. Optionally, the primary address is separated from the mirrored address by a distance of one cache line size. For example, referring to FIG. 4, the primary address Pri0 and the backup address Sec0 have a mirror relationship, the primary address Pri63 and the backup address Sec63 have a mirror relationship, the primary address Pri0 and the backup address Sec0 are separated by a distance of a cache line size, and the primary address Pri63 and the backup address Sec63 is one cache line size apart. In this way, the address calculation method is made as simple as possible, and the implementation complexity is reduced.
在一些实施例中,镜像地址与主地址之间的关系满足如下公式1。In some embodiments, the relationship between the mirror address and the master address satisfies Equation 1 below.
Secondary_PA=Primary_PA+CacheLine_Size;  公式1Secondary_PA=Primary_PA+CacheLine_Size; Formula 1
在以上公式1中,Secondary_PA表示镜像地址,Primary_PA表示主地址,CacheLine_Size表示一个缓存行尺寸。例如,参见附图4,当缓存行尺寸为64B时,主地址Pri0在Cache Line0的第一个字节,主地址Pri0对应的镜像地址Sec0在Cache Line1的第一个字节,因此Sec0=Pr0+0x40。通过上述公式1,确保MC能够通过内存读写指令的目的地址字段计算镜像地址。In the above formula 1, Secondary_PA represents the mirror address, Primary_PA represents the primary address, and CacheLine_Size represents a cache line size. For example, referring to Figure 4, when the cache line size is 64B, the main address Pri0 is in the first byte of Cache Line0, and the mirror address Sec0 corresponding to the main address Pri0 is in the first byte of Cache Line1, so Sec0=Pr0 +0x40. Through the above formula 1, it is ensured that the MC can calculate the mirror address through the destination address field of the memory read and write instructions.
在一些实施例中,主地址包括的偏移地址是根据缓存行尺寸以及虚拟地址包括的偏移地址确定的。具体来说,在未启用动态内存镜像功能时,虚拟地址通过页表翻译获得的物理地址就是实际的内存地址,即PA=Page_Base_PA+Offset_In_VA。其中,PA表示物理地址,Page_Base_PA表示物理页的基地址,Offset_In_VA表示物理页中的偏移地址。启用动态镜像功能后,虚拟地址通过页表翻译的物理地址(即Page_Base_PA+Offset_in_VA)不再等于实际的主地址(即Page_Base_PA+Offset in Memory)。假设一个页的尺寸为4千字节(Kilobyte,KB),且缓存行尺寸为64字节(byte,B),如附图4所示,实际主地址的偏移地址与虚拟地址的偏移地址(即页表中的偏移)满足如下关系:In some embodiments, the offset address included in the main address is determined according to the cache line size and the offset address included in the virtual address. Specifically, when the dynamic memory mirroring function is not enabled, the physical address obtained by translating the virtual address through the page table is the actual memory address, that is, PA=Page_Base_PA+Offset_In_VA. Among them, PA represents the physical address, Page_Base_PA represents the base address of the physical page, and Offset_In_VA represents the offset address in the physical page. After the dynamic mirroring function is enabled, the physical address translated by the virtual address through the page table (ie Page_Base_PA+Offset_in_VA) is no longer equal to the actual main address (ie Page_Base_PA+Offset in Memory). Assuming that the size of a page is 4 kilobytes (Kilobyte, KB), and the size of the cache line is 64 bytes (byte, B), as shown in Figure 4, the offset address of the actual main address and the offset of the virtual address The address (that is, the offset in the page table) satisfies the following relationship:
Offset_In_Memory=Offset_In_VA+Cache_Line_Size*[INT(Offset_In_VA/Cache_Line_Size)];Offset_In_Memory=Offset_In_VA+Cache_Line_Size*[INT(Offset_In_VA/Cache_Line_Size)];
其中,Offset_In_Memory表示主地址的偏移地址,Offset_In_VA表示虚拟地址中的偏移地址,Cache_Line_Size表示缓存行尺寸,INT表示取整运算。Among them, Offset_In_Memory represents the offset address of the main address, Offset_In_VA represents the offset address in the virtual address, Cache_Line_Size represents the size of the cache line, and INT represents the rounding operation.
根据上述关系可知,主地址的计算公式如下述公式2所示。According to the above relationship, the calculation formula of the master address is shown in the following formula 2.
Primary_PA=Page_Base_PA+Offset_In_VA+Cache_Line_Size*[INT(Offset_In_VA/Cache_Li ne_Size)];  公式2Primary_PA=Page_Base_PA+Offset_In_VA+Cache_Line_Size*[INT(Offset_In_VA/Cache_Line_Size)]; Formula 2
在上述公式2中,Primary_PA表示主地址,Page_Base_PA表示物理页的基地址,Offset_In_VA表示虚拟地址中的偏移地址,Cache_Line_Size表示缓存行尺寸,INT表示取整运算。通过上述公式2,确保MMU能够把虚拟地址正确翻译到镜像内存的主地址。In the above formula 2, Primary_PA represents the main address, Page_Base_PA represents the base address of the physical page, Offset_In_VA represents the offset address in the virtual address, Cache_Line_Size represents the cache line size, and INT represents the rounding operation. Through the above formula 2, it is ensured that the MMU can correctly translate the virtual address to the main address of the mirrored memory.
在一些实施例中,虚拟地址标识的每一个虚拟页对应于两个相邻的物理页。其中,两个相邻的物理页例如是一个物理页中最后一个位置的地址与另一个物理页中第一个位置的地址相邻。具体来说,OS是以页为单位分配一块地址连续的内存空间。为了实现动态镜像,本实施例以页为单位进行内存镜像,在分配镜像内存时,将以两个相邻连续的物理页为单位分配 内存空间。例如,参见附图4,一个页的尺寸是4KB,虚拟页是虚拟地址0至虚拟地址4095标识的一个页,目标内存空间是物理地址0至物理地址4095标识的物理页1、物理地址4096至物理地址8191标识的物理页2。In some embodiments, each virtual page identified by the virtual address corresponds to two adjacent physical pages. Wherein, two adjacent physical pages are, for example, the address of the last position in one physical page is adjacent to the address of the first position in another physical page. Specifically, the OS allocates a block of memory space with contiguous addresses in units of pages. In order to implement dynamic mirroring, this embodiment performs memory mirroring in units of pages. When allocating mirrored memory, memory space is allocated in units of two adjacent consecutive physical pages. For example, referring to FIG. 4, the size of a page is 4KB, the virtual page is a page identified by virtual address 0 to virtual address 4095, and the target memory space is physical page 1 identified by physical address 0 to physical address 4095, physical address 4096 to Physical page 2 identified by physical address 8191.
在一些实施例中,一个物理页包括一个或多个主内存空间以及一个或多个镜像内存空间。例如,参见附图4,物理页1既包括主内存空间(缓存行0主、缓存行2主),又包括镜像内存空间(缓存行1镜像、缓存行3镜像)。In some embodiments, a physical page includes one or more main memory spaces and one or more mirrored memory spaces. For example, referring to FIG. 4, physical page 1 includes both main memory space (cache line 0 main, cache line 2 main) and mirror memory space (cache line 1 mirror, cache line 3 mirror).
在一些实施例中,一个物理页中主内存空间与镜像内存空间交织分布。一个物理页中互为镜像关系的主内存空间与镜像内存空间相隔一个缓存行尺寸的距离。In some embodiments, the main memory space and the mirror memory space are interleaved in a physical page. The distance between the main memory space and the mirror memory space that are mirrored to each other in a physical page is one cache line size.
步骤S303、计算设备根据主地址和镜像地址,对主内存空间和镜像内存空间执行内存读写指令对应的操作。Step S303: The computing device performs operations corresponding to the memory read and write instructions on the main memory space and the mirrored memory space according to the main address and the mirrored address.
在一些实施例中,在启用动态镜像功能的同时,启用内存地址交织。例如,启用双路内存地址交织(2way Channel Interleave)。镜像内存空间和主内存空间位于不同的通道。例如,参见附图4,镜像地址primary0标识的内存空间与主地址primary0标识的内存空间位于不同的通道。In some embodiments, memory address interleaving is enabled while the dynamic mirroring function is enabled. For example, enable 2way Channel Interleave. The mirrored memory space and the main memory space are in different channels. For example, referring to FIG. 4 , the memory space identified by the mirror address primary0 and the memory space identified by the primary address primary0 are located in different channels.
通过这种方式,一方面,由于镜像内存空间和主内存空间这两个内存空间位于不同的通道,镜像内存空间和主内存空间在物理上互相独立,内存控制器能够利用多个通道并行地对镜像内存空间和主内存空间,从而提升读写性能。例如,上述内存读写指令为写指令,主内存空间位于通道0,镜像内存空间位于通道1,内存控制器向通道0中的主内存空间写入数据的同时,向通道1中的镜像内存空间写入数据。显然,相对于通过同一个通道先后访对镜像内存空间和主内存空间来说,读写性能更高。另一方面,由于镜像内存空间和主内存空间能够同时进行数据读写,保证镜像内存空间与主内存空间数据保持同步,避免镜像内存空间和主内存空间保存的数据不一致而导致出错。In this way, on the one hand, since the mirrored memory space and the main memory space are located in different channels, the mirrored memory space and the main memory space are physically independent of each other, and the memory controller can use multiple channels to Mirror memory space and main memory space to improve read and write performance. For example, the above memory read and write instructions are write instructions, the main memory space is located in channel 0, and the mirror memory space is located in channel 1. When the memory controller writes data to the main memory space in channel 0, it writes data to the mirror memory space in channel 1. data input. Obviously, compared to accessing the mirrored memory space and the main memory space successively through the same channel, the read and write performance is higher. On the other hand, since the mirrored memory space and the main memory space can read and write data at the same time, it is ensured that the mirrored memory space and the main memory space data are kept synchronized, and errors caused by inconsistent data saved in the mirrored memory space and the main memory space are avoided.
在一些实施例中,计算设备确定主地址和备地址之后,判断主地址对应的ECC空间是否包括镜像指示信息,并判断镜像地址对应的ECC空间是否包括镜像指示信息;响应于主地址对应的ECC空间以及镜像地址对应的ECC空间均包括镜像指示信息,计算设备根据主地址和镜像地址,对主内存空间和镜像内存空间执行内存读写指令对应的操作。In some embodiments, after determining the primary address and the secondary address, the computing device determines whether the ECC space corresponding to the primary address includes mirroring indication information, and determines whether the ECC space corresponding to the mirroring address includes mirroring indication information; in response to the ECC corresponding to the primary address Both the space and the ECC space corresponding to the mirrored address include mirroring indication information, and the computing device performs operations corresponding to the memory read and write instructions on the main memory space and the mirrored memory space according to the main address and the mirrored address.
可选地,判断ECC空间是否包括镜像指示信息的动作具体由计算设备中的MC执行。具体地,MC接收到内存读写指令时,判断内存读写指令是否是镜像读写指令,如果内存读写指令是镜像读写指令,则MC确定镜像地址,并访问主地址对应的ECC空间以及镜像地址对应的ECC空间,MC判断主地址对应的ECC空间以及镜像地址对应的ECC空间是否均包括镜像指示信息。如果主地址对应的ECC空间以及镜像地址对应的ECC空间均包括镜像指示信息,MC执行镜像读写操作,即对主内存空间和镜像内存空间同时执行读数据操作或写数据操作。如果主地址对应的ECC空间不包括镜像指示信息,或者镜像地址对应的ECC空间不包括镜像指示信息,MC确定对镜像内存访问不合法,MC拒绝执行镜像读写操作。Optionally, the action of judging whether the ECC space includes mirroring indication information is specifically performed by the MC in the computing device. Specifically, when the MC receives the memory read/write command, it determines whether the memory read/write command is a mirror read/write command. If the memory read/write command is a mirror read/write command, the MC determines the mirror address, and accesses the ECC space corresponding to the main address and For the ECC space corresponding to the mirror address, the MC judges whether the ECC space corresponding to the main address and the ECC space corresponding to the mirror address both include mirror indication information. If both the ECC space corresponding to the main address and the ECC space corresponding to the mirror address include mirror indication information, the MC performs mirror read and write operations, that is, perform read data operations or write data operations on the main memory space and the mirror memory space at the same time. If the ECC space corresponding to the primary address does not include mirroring indication information, or the ECC space corresponding to the mirroring address does not include mirroring indication information, the MC determines that the access to the mirrored memory is illegal, and the MC refuses to perform mirroring read and write operations.
在一些实施例中,在ECC空间中启用一个或多个比特位作为镜像指示信息字段,以便MC识别启用镜像内存的内存空间。若ECC空间中的镜像指示信息字段置位(即ECC空间包括镜像指示信息),表示目标内存空间已启用内存镜像。若ECC空间中的镜像指示信息字段没有置位(即ECC空间不包括镜像指示信息),表示目标内存空间没有启用内存镜像。例如,参见附图4,主地址Pri0位于缓存行CacheLine0,镜像地址Sec0位于缓存行CacheLine1。 若CacheLine0对应的ECC空间、CacheLine1对应的ECC空间均包括镜像指示信息,则允许对主地址Pri0标识的内存空间以及镜像地址Sec0标识的内存空间进行镜像读写操作(比如同时写入数据)。In some embodiments, one or more bits are enabled in the ECC space as a mirror indication information field for the MC to identify a memory space in which mirror memory is enabled. If the mirroring indication information field in the ECC space is set (that is, the ECC space includes mirroring indication information), it means that memory mirroring is enabled in the target memory space. If the mirroring indication information field in the ECC space is not set (that is, the ECC space does not include mirroring indication information), it means that memory mirroring is not enabled in the target memory space. For example, referring to FIG. 4, the primary address Pri0 is located in the cache line CacheLine0, and the mirror address Sec0 is located in the cache line CacheLine1. If the ECC space corresponding to CacheLine0 and the ECC space corresponding to CacheLine1 both include mirroring indication information, mirroring read and write operations (such as simultaneous data writing) are allowed to the memory space marked by the primary address Pri0 and the memory space marked by the mirror address Sec0.
本实施例提供的方法,在虚拟地址对应的页表项中启用字段携带镜像指示信息,从而指明虚拟地址标识的内存空间已经启用了镜像保护。在收到内存读写指令时,如果发现内存读写指令携带的虚拟地址对应的页表项存在镜像指示信息,则主地址和备地址对应的两个内存空间均进行读写操作,从而支持了动态内存镜像功能,能够一定程度上解决现有内存镜像方案的局限性。In the method provided by this embodiment, the enabling field in the page table entry corresponding to the virtual address carries mirroring indication information, thereby indicating that mirroring protection has been enabled in the memory space identified by the virtual address. When a memory read/write command is received, if it is found that the page table entry corresponding to the virtual address carried by the memory read/write command has mirror indication information, the two memory spaces corresponding to the primary address and the standby address are both read and written, thus supporting The dynamic memory mirroring function can solve the limitations of the existing memory mirroring scheme to a certain extent.
在一些实施例中,通过对MMU和MC来实现上述镜像内存读写的处理流程。具体地,MMU用于对动态镜像内存执行从虚拟地址到物理地址的翻译处理流程。当MMU检测到虚拟地址对应的页表项中镜像指示信息字段为1时,MMU按照上述公式2计算主内存空间的物理地址。In some embodiments, the above-mentioned processing flow of reading and writing the mirrored memory is implemented by the MMU and the MC. Specifically, the MMU is used to perform a translation process flow from a virtual address to a physical address on the dynamic mirror memory. When the MMU detects that the mirror indication information field in the page table entry corresponding to the virtual address is 1, the MMU calculates the physical address of the main memory space according to the above formula 2.
MC执行镜像内存读写的处理流程包括下述步骤1至步骤3。The processing flow of the MC performing mirror memory read and write includes the following steps 1 to 3.
步骤1、拒绝非“镜像读写”指令。 Step 1. Reject non-"mirror read and write" commands.
具体地,MC接收到MMU发送的内存读写指令时,MC检测内存读写指令的目的地址对应的ECC中镜像指示信息字段的内容是否为1。当镜像指示信息字段为1时,如果MC收到的是非“镜像读/写”指令,则MC拒绝执行指令,返回非法访问,从而确保镜像保护的页只能用于镜像保护操作。Specifically, when the MC receives the memory read/write instruction sent by the MMU, the MC detects whether the content of the mirror indication information field in the ECC corresponding to the destination address of the memory read/write instruction is 1. When the mirror indication information field is 1, if the MC receives a non-mirrored read/write command, the MC refuses to execute the command and returns an illegal access, thereby ensuring that mirror-protected pages can only be used for mirror-protected operations.
其中,被分配为镜像内存的页,其对应的ECC的镜像指示信息为1;由OS的缺页中断函数在分配物理页时发起ECC的镜像指示信息字段置1操作;当物理页被释放时,OS的物理页回收函数发起ECC的镜像指示信息字段清零操作。MC通过ECC的镜像指示信息字段识别物理内存是否启用动态镜像功能,能够区分普通内存读写与镜像内存读写指令,从解决MC不能支持动态内存镜像的问题。Among them, the page allocated as mirrored memory, the corresponding ECC mirroring indication information is 1; the page fault interrupt function of the OS initiates the ECC mirroring indication information field setting operation when the physical page is allocated; when the physical page is released , the physical page recovery function of the OS initiates the zero-clearing operation of the mirror indication information field of the ECC. The MC identifies whether the dynamic mirroring function is enabled in the physical memory through the mirroring instruction information field of the ECC, and can distinguish between ordinary memory read and write instructions and mirrored memory read and write instructions, thus solving the problem that the MC cannot support dynamic memory mirroring.
步骤2、MC执行正常镜像读/写指令。Step 2. The MC executes normal mirror read/write commands.
MC收到的“镜像读写”指令中目的地址是MMU通过公式2翻译得到的主地址Pri_PA。MC根据公式1计算镜像地址Sec_PA,并同时对主内存空间和镜像内存空间发起指令规定的操作(读/写),从而确保主地址与镜像地址写的一致性。当镜像地址Sec_PA与主地址Pri_PA不属于同一个MC控制的通道时,收到指令的MC负责与镜像地址Sec_PA归宿的MC交互完成对应的指令操作。The destination address in the "mirror read and write" command received by the MC is the primary address Pri_PA translated by the MMU through formula 2. The MC calculates the mirror address Sec_PA according to formula 1, and simultaneously initiates an operation (read/write) specified by the instruction to the main memory space and the mirror memory space, thereby ensuring the consistency of the main address and mirror address writing. When the mirror address Sec_PA and the primary address Pri_PA do not belong to the same channel controlled by the MC, the MC that receives the command is responsible for interacting with the MC to which the mirror address Sec_PA belongs to complete the corresponding command operation.
步骤3、如果MC执行内存读写指令遇到错误,则按照下述动态镜像内存故障处理流程中的步骤3、步骤4、步骤5、步骤6、步骤7处理。Step 3. If the MC encounters an error when executing the memory read/write command, follow steps 3, 4, 5, 6, and 7 in the following dynamic mirror memory fault handling process.
以上介绍了镜像内存读写的处理流程,下面对动态镜像内存分配处理流程进行介绍。The above describes the processing flow of mirror memory read and write, and the following describes the dynamic mirror memory allocation processing flow.
在一些实施例中,在接收内存读写指令之前,计算设备接收指定对象的内存分配请求;响应于指定对象的镜像标志置为设定值,计算设备为指定对象分配目标内存空间。In some embodiments, before receiving the memory read/write instruction, the computing device receives a memory allocation request for the specified object; in response to the specified object's mirroring flag being set to a set value, the computing device allocates the target memory space for the specified object.
指定对象是指计算机中允许占用内存空间的软件模块。例如,指定对象包括而不限于进程、内核、进程的部分VMA段、内核中的部分模块等。内存分配请求指示为指定对象分配内存空间。在一些实施例中,不同类型的指定对象具有不同的镜像标志。例如,内核的镜像 标志与进程的镜像标志不同。Specified objects refer to software modules that are allowed to occupy memory space in the computer. For example, specified objects include, but are not limited to, a process, a kernel, a portion of a VMA segment of a process, a portion of a module in the kernel, and the like. A memory allocation request indicates to allocate memory space for the specified object. In some embodiments, different types of designated objects have different mirror marks. For example, the kernel's mirror flag is different from the process' mirror flag.
通过上述方式,针对指定对象运行时实际请求分配的内存采用镜像保护,避免预设过大的镜像内存导致内存资源浪费,同时避免预设的镜像内存不足导致业务中断。In the above manner, mirror protection is adopted for the memory actually requested to be allocated when the specified object is running, so as to avoid the waste of memory resources caused by the preset mirror memory that is too large, and avoid the service interruption caused by insufficient mirror memory.
在一些实施例中,接收指定对象的内存分配请求之后,计算设备向虚拟地址对应的页表项、主地址对应的ECC空间以及镜像地址对应的ECC空间分别写入镜像指示信息。例如,计算设备在分配镜像内存的过程中,将虚拟地址对应的页表项中的镜像指示信息字段、主地址对应的ECC空间中的镜像指示信息字段以及镜像地址对应的ECC空间中的镜像指示信息字段均置为1。In some embodiments, after receiving the memory allocation request for the specified object, the computing device writes mirror indication information to the page table entry corresponding to the virtual address, the ECC space corresponding to the main address, and the ECC space corresponding to the mirror address, respectively. For example, in the process of allocating mirrored memory, the computing device uses the mirroring indication information field in the page table entry corresponding to the virtual address, the mirroring indication information field in the ECC space corresponding to the main address, and the mirroring indication in the ECC space corresponding to the mirror address. Information fields are all set to 1.
通过上述方式,将指定对象对应的页表项以及ECC空间中设置镜像指示信息,便于计算机各硬件识别指定对象的内存受到镜像保护。In the above manner, mirroring indication information is set in the page table entry corresponding to the specified object and the ECC space, so that each hardware of the computer can identify that the memory of the specified object is protected by mirroring.
在一些实施例中,通过修改OS的内存管理模块实现动态镜像内存分配处理流程。具体来说,对OS内存管理模块的内存分配函数修改,在内存分配函数中,增加处理镜像内存分配时对PTE的镜像指示信息置为1的模块,表明该内存空间启用镜像保护。对OS内存管理模块的缺页中断处理函数修改,在缺页中断处理函数中增加镜像内存分配物理页面的模块。缺页中断处理函数在检测到PTE的镜像指示信息为1时,也把实际分配的物理页对应的ECC的镜像指示信息置为1,以便内存控制器识别并按照动态镜像内存的要求进行处理。In some embodiments, the dynamic mirror memory allocation process flow is implemented by modifying the memory management module of the OS. Specifically, modify the memory allocation function of the OS memory management module. In the memory allocation function, add a module that sets the mirroring indication information of the PTE to 1 when processing mirrored memory allocation, indicating that mirroring protection is enabled for this memory space. Modify the page fault interrupt processing function of the OS memory management module, and add a module for mirroring memory allocation to physical pages in the page fault interrupt processing function. When the page fault interrupt processing function detects that the mirroring indication information of the PTE is 1, it also sets the mirroring indication information of the ECC corresponding to the actually allocated physical page to 1, so that the memory controller can identify and process according to the requirements of dynamic mirroring memory.
示例性地,动态镜像内存分配函数分配虚拟地址的处理流程包括以下步骤1至步骤3。Exemplarily, the processing flow for allocating virtual addresses by the dynamic mirror memory allocation function includes the following steps 1 to 3.
步骤1、OS为进程分配新的虚拟地址空间。 Step 1. The OS allocates a new virtual address space for the process.
其中,gfp分配标志新增GFP_MIRROR(内核态)和vma新增标志VM_MIRROR(用户态)。GFP_MIRROR(内核态)是一种GFP分配标志。GFP_MIRROR适用于内核态的进程。VM_MIRROR是一种VMA标志。VM_MIRROR适用于用户态的进程。通过gfp分配标志新增GFP_MIRROR(内核态)和vma新增标志VM_MIRROR(用户态),解决内存分配函数不能支持内存动态镜像的管理的问题,支持动态镜像编程接口。Among them, GFP_MIRROR (kernel mode) is added to the gfp allocation flag and VM_MIRROR (user mode) is added to the vma flag. GFP_MIRROR (kernel state) is a GFP allocation flag. GFP_MIRROR applies to kernel mode processes. VM_MIRROR is a VMA flag. VM_MIRROR applies to user-mode processes. Added GFP_MIRROR (kernel mode) and vma new flag VM_MIRROR (user mode) through the gfp allocation flag to solve the problem that the memory allocation function cannot support the management of memory dynamic mirroring, and support the dynamic mirroring programming interface.
当malloc等内存分配函数需要新增虚拟地址空间时,通过系统调用brk或do_map函数分配新的虚拟地址空间。When a memory allocation function such as malloc needs to add a new virtual address space, the system calls the brk or do_map function to allocate a new virtual address space.
步骤2、OS在进程页表新增加对应虚拟地址的页表项。Step 2: The OS adds a page table entry corresponding to the virtual address in the process page table.
其中,以页为单位,在页表中为新增的地址空间分配页表项,此时页表项里记录了页的基地址,对应的物理页基地址为空。Among them, in the unit of page, a page table entry is allocated for the newly added address space in the page table. At this time, the base address of the page is recorded in the page table entry, and the corresponding physical page base address is empty.
步骤3、OS将新增PTE的镜像指示信息字段置为1。Step 3. The OS sets the mirroring indication information field of the newly added PTE to 1.
当镜像指示信息字段为1时,MMU就调用公式2正确地把虚拟地址翻译主地址;同时缺页中断处理函数也因此为此虚拟地址分配两个连续的物理页,第一个物理页的基地址被记录到页表项的物理地址中。When the mirror indication information field is 1, the MMU calls formula 2 to correctly translate the virtual address to the main address; at the same time, the page fault interrupt handler also allocates two consecutive physical pages for this virtual address, the base of the first physical page. The address is recorded into the physical address of the page table entry.
示例性地,动态镜像内存函数分配物理页的处理流程包括以下步骤1至步骤3。Exemplarily, the processing flow of allocating physical pages by the dynamic mirroring memory function includes the following steps 1 to 3.
步骤1、OS判断虚拟地址对应页表项的镜像指示信息字段是否为1。 Step 1. The OS determines whether the mirror indication information field of the page table entry corresponding to the virtual address is 1.
其中,当页表项的镜像指示信息字段为1,表明该虚拟地址对应的是动态内存镜像,则OS分配两个连续的物理页。当页表项的镜像指示信息字段为0,OS按照原流程分配一个物理页。Wherein, when the image indication information field of the page table entry is 1, indicating that the virtual address corresponds to a dynamic memory image, the OS allocates two consecutive physical pages. When the mirror indication information field of the page table entry is 0, the OS allocates a physical page according to the original process.
步骤2、OS为虚拟地址分配两个连续的物理页。Step 2. The OS allocates two consecutive physical pages to the virtual address.
具体地,在空闲的物理页空间寻找两个连续的物理页,并把两个连续物理页中第一个物理页的基地址记录在虚拟地址对应的页表项的物理地址中。如果没有两个连续物理页,则尝试移动一些物理页中保存的数据,从而构造两个连续的物理页,并分配构造出的两个连续物理页。Specifically, two consecutive physical pages are searched in the free physical page space, and the base address of the first physical page in the two consecutive physical pages is recorded in the physical address of the page table entry corresponding to the virtual address. If there are not two contiguous physical pages, try to move the data held in some physical pages, thus constructing two contiguous physical pages, and allocate the constructed two contiguous physical pages.
步骤3、OS把对应ECC的镜像指示信息字段置为1。Step 3. The OS sets the mirror indication information field corresponding to the ECC to 1.
OS把新分配的物理页的基地址记录到页表项的物理地址字段。调用底层接口把新分配物理页对应ECC的镜像指示信息字段置为1,确保MC也按照动态镜像内存管理该物理页。此外,将已分配的两个物理页同时标记为保留(Reserved),避免被重复分配。The OS records the base address of the newly allocated physical page into the physical address field of the page table entry. The underlying interface is called to set the mirror indication information field of the ECC corresponding to the newly allocated physical page to 1, to ensure that the MC also manages the physical page according to the dynamic mirror memory. In addition, the allocated two physical pages are marked as reserved (Reserved) at the same time to avoid repeated allocation.
下面对动态镜像内存物理页面回收处理流程进行介绍。在一些实施例中,向OS内存管理的内存回收处理函数中增加回收镜像内存物理页的模块。具体地,动态镜像内存回收函数处理流程包括下述步骤1至步骤3。The following describes the process of reclaiming physical pages of dynamic mirrored memory. In some embodiments, a module for reclaiming physical pages of mirrored memory is added to the memory reclamation processing function of OS memory management. Specifically, the processing flow of the dynamic mirror memory recycling function includes the following steps 1 to 3.
步骤1、判断虚拟地址对应页表项的镜像指示信息字段是否为1。 Step 1. Determine whether the mirror indication information field of the page table entry corresponding to the virtual address is 1.
当页表项的镜像指示信息字段为1,表明该虚拟地址对应的内存空间启用了动态内存镜像,则将物理地址字段对应的两个连续的物理页都回收。当页表项的镜像指示信息字段为0,则按照原来的流程回收页表项中物理地址字段对应的一个物理页。When the mirror indication information field of the page table entry is 1, indicating that dynamic memory mirroring is enabled in the memory space corresponding to the virtual address, two consecutive physical pages corresponding to the physical address field are reclaimed. When the mirror indication information field of the page table entry is 0, a physical page corresponding to the physical address field in the page table entry is reclaimed according to the original process.
步骤2、页回收函数将对应ECC的镜像指示信息字段置为0。Step 2. The page recycling function sets the mirror indication information field corresponding to the ECC to 0.
具体地,根据虚拟地址获得对应页表项的物理地址字段携带的值。调用底层接口把物理地址对应的两个连续物理页的ECC的镜像指示信息字段置为0,确保MC按照普通内存管理该物理页。Specifically, the value carried by the physical address field of the corresponding page table entry is obtained according to the virtual address. The underlying interface is called to set the mirroring indication information field of the ECC of two consecutive physical pages corresponding to the physical address to 0, so as to ensure that the MC manages the physical pages according to ordinary memory.
步骤3、页回收函数回收物理地址对应的主页以及镜像页。Step 3. The page reclaim function reclaims the home page and the mirror page corresponding to the physical address.
页回收函数把虚拟地址对应页表项的物理地址字段清空;将两个物理页放回空闲页面链表等待分配。The page recycling function clears the physical address field of the page table entry corresponding to the virtual address; puts the two physical pages back into the free page linked list for allocation.
下面对动态内存镜像管理的配置和命令的流程进行介绍。在一些实施例中,接收指定对象的内存分配请求之前,方法还包括:响应于内存镜像指令,计算设备将指定对象的镜像标志修改为设定值。其中,内存镜像指令指示针对指定对象所需的内存空间启用内存镜像。内存镜像指令例如由管理员的操作触发。内存镜像指令包括指定对象的标识。例如,在指定对象为进程的情况下,内存镜像指令包括进程的进程号(Process ID,PID)。通过新增内存镜像指令,能够指定哪些对象启用内存镜像保护,并且计算机能够在进程启动或者运行时修改进程的镜像标志,从而满足进程的动态镜像管理需求。The following describes the configuration and command flow of dynamic memory mirroring management. In some embodiments, before receiving the memory allocation request for the specified object, the method further includes: in response to the memory mirroring instruction, the computing device modifies the mirroring flag of the specified object to a set value. Among them, the memory mirroring instruction instructs to enable memory mirroring for the memory space required by the specified object. The memory mirroring instruction is triggered, for example, by the operation of the administrator. Memory mirroring instructions include the identification of the specified object. For example, in the case where the specified object is a process, the memory mirroring instruction includes the process ID (Process ID, PID) of the process. By adding a memory mirroring instruction, you can specify which objects enable memory mirroring protection, and the computer can modify the mirroring flag of the process when the process starts or runs, so as to meet the dynamic mirroring management requirements of the process.
在一些实施例中,配置和命令的流程包括内核镜像保护流程和进程内存镜像保护流程。In some embodiments, the configuration and command flow includes a kernel image protection flow and a process memory image protection flow.
内核镜像保护流程是指在现有系统配置文件增加新的配置项,或定义新的配置文件,用于定义内核的那些部分启用动态内存镜像保护,OS启动过程中根据配置来为内核分配镜像保护的物理页,流程包括下述步骤1至步骤3。The kernel image protection process refers to adding new configuration items to the existing system configuration file, or defining a new configuration file, which is used to define those parts of the kernel to enable dynamic memory image protection. During the OS startup process, image protection is allocated to the kernel according to the configuration. physical page, the process includes the following steps 1 to 3.
步骤1、操作系统启动(OS Boot)并解析配置文件中关于内核镜像保护的配置。 Step 1. The operating system starts (OS Boot) and parses the configuration about the protection of the kernel image in the configuration file.
步骤2、根据配置文件,为内核中需要镜像保护的模块分配镜像物理页。Step 2. According to the configuration file, allocate mirrored physical pages to modules in the kernel that need mirroring protection.
步骤3、运行中为内核分配镜像物理页。Step 3. Allocate mirrored physical pages for the kernel during operation.
其中,为内核新增内存需求分配镜像物理页;或者,在内存故障时隔离故障页并分配新镜像物理页。Among them, the mirrored physical pages are allocated for the new memory requirements of the kernel; or, when the memory fails, the faulty pages are isolated and new mirrored physical pages are allocated.
进程内存镜像保护流程包括下述步骤1至步骤3。其中,下述mirrorable命令为上述内存镜像指令。The process memory image protection process includes the following steps 1 to 3. The following mirrorable commands are the above memory mirroring commands.
步骤1、用mirrorable命令启动进程并镜像进程的内存。 Step 1. Start the process with the mirrorable command and mirror the memory of the process.
MML:#mirroable program;MML: #mirroable program;
mirroable设置task_struct->mirrorable为真(True),进程内存启用镜像保护,已经分配的虚拟地址对应的页表项的镜像指示信息字段全部置为1。调用execX()函数启动目标进程,目标继承全部镜像内存设置,后续分配的内存也自动启动镜像保护。mirroable sets task_struct->mirrorable to true (True), the process memory enables mirror protection, and the mirror indication information fields of the page table entries corresponding to the allocated virtual addresses are all set to 1. Call the execX() function to start the target process, the target inherits all mirror memory settings, and the subsequently allocated memory also automatically starts mirror protection.
步骤2、进程启动后运行mirrorable命令镜像进程的内存。Step 2. After the process starts, run the mirrorable command to mirror the memory of the process.
MML:#mirroable pid;MML: #mirroable pid;
mirroable命令先挂起pid进程;修改pid进程task_struct->mirrorable为真(True);把pid进程的全部虚拟地址对应页表项的镜像指示信息字段全部置为1;为pid进程已经分配物理页分配新的镜像物理页,并将现有物理页数据复制到镜像物理页,用镜像物理页物理地址刷新虚拟地址对应的物理地址;释放原先未镜像的物理页;激活pid进程继续运行。The mirroable command suspends the pid process first; modifies the pid process task_struct->mirrorable to be true (True); sets all the mirror indication information fields of the page table entries corresponding to all virtual addresses of the pid process to 1; allocates physical pages for the pid process Create a new mirrored physical page, copy the existing physical page data to the mirrored physical page, refresh the physical address corresponding to the virtual address with the physical address of the mirrored physical page; release the original unmirrored physical page; activate the pid process to continue running.
步骤3、通过编程接口管理进程内存镜像Step 3. Manage process memory mirroring through the programming interface
判断当前版本的操作系统是否支持动态内存镜像,并判断CPU和MC是否支持动态内存镜像。如果操作系统、CPU和MC支持动态内存镜像,调用支持镜像内存的函数申请内存空间,相关函数自动完成镜像保护页面虚拟地址对应页表项的镜像指示信息全部置为1;缺页中断处理函数自动分配、回收镜像物理页。Check whether the current version of the operating system supports dynamic memory mirroring, and whether the CPU and MC support dynamic memory mirroring. If the operating system, CPU, and MC support dynamic memory mirroring, call the functions that support mirrored memory to apply for memory space, and the related functions automatically complete the mirroring protection page. The virtual address of the corresponding page table entry is all set to 1; Allocate and reclaim mirrored physical pages.
需要说明的是,通过mirroable命令是对进程所有内存模块全部镜像,也可以考虑选择进程的部分VMA段进行镜像保护。如果需要保护特定页面,可通过编程接口,由程序员来完成。It should be noted that, through the mirrorable command, all memory modules of the process are mirrored, and some VMA segments of the process can also be selected for mirror protection. If a specific page needs to be protected, it can be done by the programmer through the programming interface.
此外,如果OS可以支持双内核(kernel),可以通过mirroable命令启动一个内存镜像保护新内核,然后业务全部交给新内核管理,并释放未镜像保护的旧内核,这样就可以在运行时(Runtime)把内核切换到镜像保护状态。In addition, if the OS can support dual kernels, you can start a memory mirror to protect the new kernel through the mirrorable command, and then hand over all the business to the new kernel for management, and release the old kernel without mirror protection, so that you can run ) switches the kernel to an image-protected state.
下面对动态镜像内存物理页面故障处理流程进行介绍。The following describes the processing flow of the physical page fault of the dynamic mirror memory.
计算设备在运行过程中,响应于上述镜像内存空间发生故障,隔离镜像内存空间;计算设备为虚拟地址重新分配镜像内存空间,计算设备将主内存空间保存的数据写入至重新分配的镜像内存空间。During operation, the computing device isolates the mirrored memory space in response to the above-mentioned fault in the mirrored memory space; the computing device reallocates the mirrored memory space for the virtual address, and the computing device writes the data stored in the main memory space to the reallocated mirrored memory space .
例如,计算设备从内存中空闲可用的内存空间中,选择与主内存空间容量相同的内存空间,作为重新分配的镜像内存空间。For example, the computing device selects a memory space with the same capacity as the main memory space from the free and available memory space in the memory as the reallocated mirror memory space.
此外,计算设备还对故障的镜像内存空间添加标记。标记用于指示镜像内存空间处于故障状态。计算机后续在分配内存时,不会分配已标记的内存空间,从而避免故障的镜像内存空间被分配时引起的问题。动态镜像内存故障处理流程包括下述步骤1至步骤7。In addition, the computing device also tags the failed mirrored memory space. Flags are used to indicate that the mirrored memory space is in a failed state. When the computer subsequently allocates memory, it will not allocate the marked memory space, thereby avoiding problems caused when the faulty mirrored memory space is allocated. The dynamic mirror memory fault handling process includes the following steps 1 to 7.
步骤1、系统正常运行时,通过自动巡检内存发现故障,或者在访问内存时遇到故障。 Step 1. When the system is running normally, faults are found through automatic memory inspection, or faults are encountered when accessing memory.
步骤2、计算设备的硬件确定内存中的故障页,触发中断,进入步骤3和步骤4。具体地, 当MC执行镜像读写指令遇到不可纠正错误(Uncorrectable Error,UCE)时,通过中断通知OS进行数据恢复和故障页隔离。Step 2: The hardware of the computing device determines the faulty page in the memory, triggers an interrupt, and proceeds to Step 3 and Step 4. Specifically, when the MC encounters an uncorrectable error (Uncorrectable Error, UCE) while executing the mirror read/write instruction, it notifies the OS through an interrupt to perform data recovery and fault page isolation.
步骤3、计算设备从正常页恢复数据。Step 3. The computing device restores data from the normal page.
步骤4、计算设备的OS或虚拟机监视器(Virtual Machine Monitor,VMM)隔离故障页,进入步骤5,并进入步骤6或步骤7。Step 4. The OS or virtual machine monitor (Virtual Machine Monitor, VMM) of the computing device isolates the fault page, proceeds to step 5, and proceeds to step 6 or step 7.
步骤5、计算设备的OS或VMM重新分配镜像页。Step 5. The OS or VMM of the computing device reallocates the mirror page.
步骤6、如果异常数量低于阈值或者可用内存高于阈值,计算设备产生异常告警。Step 6. If the number of exceptions is lower than the threshold or the available memory is higher than the threshold, the computing device generates an exception alarm.
步骤7、如果异常数量高于阈值或者可用内存低于阈值,计算设备产生故障告警。Step 7. If the number of exceptions is higher than the threshold or the available memory is lower than the threshold, the computing device generates a fault alarm.
下面对本实施例提供的动态镜像内存的接口进行介绍。动态镜像内存的接口包括数据结构定义、用户态接口、内核态接口等方面。通过动态内存镜像的开发应用程序接口(Application Programming Interface,API),能够提供精细化的动态内存管理开发接口。下面从数据结构定义、用户态接口和内核态接口分别介绍本实施例提供的API。The interface of the dynamic mirror memory provided by this embodiment is introduced below. The interface of dynamic mirror memory includes data structure definition, user mode interface, kernel mode interface and so on. Through the application programming interface (Application Programming Interface, API) of dynamic memory mirroring, a refined dynamic memory management development interface can be provided. The following describes the API provided by this embodiment from the data structure definition, the user-mode interface, and the kernel-mode interface.
1、数据结构定义1. Data structure definition
1.1定义了特性配置:CONFIG_ACPI_MIRROR_MEMORY。1.1 defines the feature configuration: CONFIG_ACPI_MIRROR_MEMORY.
1.2定义了管理结构:mirror_info。1.2 defines the management structure: mirror_info.
1.3定义vm_stat引用计数,新增:NR_FREE_MIRROR_PAGES。1.3 Define vm_stat reference count, new: NR_FREE_MIRROR_PAGES.
1.4编程接口:gfp分配标志新增GFP_MIRROR(内核态)。1.4 Programming interface: Added GFP_MIRROR (kernel mode) to the gfp allocation flag.
1.5编程接口:vma新增标志VM_MIRROR(用户态)。1.5 Programming interface: VM_MIRROR (user mode) is added to vma.
1.6非编程接口:task_struct->mirrorable,全局变量mirrorable。1.6 Non-programming interface: task_struct->mirrorable, global variable mirrorable.
2、用户态接口(编程/非编程)2. User mode interface (programming/non-programming)
2.1 mmap(MAP_MIRROR)->vma(VM_MIRROR)->alloc_page(GFP_MIRROR)。2.1 mmap(MAP_MIRROR)->vma(VM_MIRROR)->alloc_page(GFP_MIRROR).
2.2 malloc(xx)->madvise(MAP_MIRROR)->vma(VM_MIRROR)->alloc_page(GFP_MIRRO R)。2.2 malloc(xx)->madvise(MAP_MIRROR)->vma(VM_MIRROR)->alloc_page(GFP_MIRRO R).
2.3 syscall->task_struct->mirrorable。2.3 syscall->task_struct->mirrorable.
2.4新增命令mirrorable用于运行时修改镜像配置:/proc/pid/mirrorable。2.4 The new command mirrorable is used to modify the mirror configuration at runtime: /proc/pid/mirrorable.
3、内核态接口(编程/非编程)3. Kernel mode interface (programming/non-programming)
3.1 alloc_page(GFP_MIRROR);3.1 alloc_page(GFP_MIRROR);
3.2 /proc/sys/vm/mirrorable->全局变量mirrorable。3.2 /proc/sys/vm/mirrorable->global variable mirrorable.
本实施例通过提供上述动态内存镜像编程接口,可以实现以页为单位的动态内存镜像。In this embodiment, by providing the above-mentioned dynamic memory mirroring programming interface, dynamic memory mirroring in units of pages can be implemented.
附图5是本申请实施例提供的一种内存读写指令的执行装置的结构示意图。附图5所示的装置500例如实现附图3所示方法中计算设备的功能。FIG. 5 is a schematic structural diagram of a device for executing a memory read/write instruction provided by an embodiment of the present application. The apparatus 500 shown in FIG. 5 , for example, implements the functions of the computing device in the method shown in FIG. 3 .
请参考附图5,装置500包括接收单元501、确定单元502和读写单元503。装置500中的各个单元全部或部分地通过软件、硬件、固件或者其任意组合来实现。接收单元501用于支持装置500执行S301。确定单元502用于支持装置500执行S302。读写单元503用于支持装置500执行S303。Referring to FIG. 5 , the apparatus 500 includes a receiving unit 501 , a determining unit 502 and a reading and writing unit 503 . Each unit in the apparatus 500 is implemented in whole or in part by software, hardware, firmware or any combination thereof. The receiving unit 501 is configured to support the apparatus 500 to execute S301. The determining unit 502 is configured to support the apparatus 500 to perform S302. The read/write unit 503 is used to support the device 500 to execute S303.
可选地,装置500还包括分配单元,分配单元用于支持装置500执行分配内存空间的步骤。Optionally, the apparatus 500 further includes an allocation unit configured to support the apparatus 500 to perform the step of allocating memory space.
可选地,读写单元503还用于支持装置500执行写入镜像指示信息、将指定对象的镜像标志修改为设定值的步骤。Optionally, the read-write unit 503 is further configured to support the apparatus 500 to perform the steps of writing the mirroring indication information and modifying the mirroring flag of the specified object to a set value.
可选地,装置500还包括隔离单元,隔离单元用于支持装置500执行隔离故障的内存空间的步骤。Optionally, the apparatus 500 further includes an isolation unit configured to support the apparatus 500 to perform the step of isolating the faulty memory space.
附图5所描述的装置实施例仅仅是示意性的,例如,上述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。附图5中上述各个单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。例如,采用软件实现时,上述确定单元502和读写单元503可以是由附图1中的处理器101或处理器105读取存储器102中存储的程序代码后,生成的软件功能单元来实现。附图5中上述各个单元也可以由计算设备中的不同硬件分别实现,例如确定单元502由附图1中的至少一个处理器101中的一部分处理资源(例如多核处理器中的一个核或两个核)实现,而读写单元503由附图1中处理器101中的其余部分处理资源(例如多核处理器中的其他核),或者采用现场可编程门阵列(field-programmable gate array,FPGA)、或协处理器等可编程器件来完成。接收单元501由附图1中的网络接口103实现。显然上述功能单元也可以采用软件硬件相结合的方式来实现,例如确定单元502由硬件可编程器件实现,而读写单元503是由CPU读取存储器中存储的程序代码后,生成的软件功能单元。The apparatus embodiment described in FIG. 5 is only schematic, for example, the division of the above-mentioned units is only a logical function division, and there may be other division methods in actual implementation, for example, multiple units or components may be combined or Integration into another system, or some features can be ignored, or not implemented. Each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit. The above-mentioned units in FIG. 5 can be implemented in the form of hardware, and can also be implemented in the form of software functional units. For example, when implemented in software, the above determination unit 502 and read/write unit 503 may be implemented by software functional units generated after the processor 101 or the processor 105 in FIG. 1 reads the program code stored in the memory 102 . The above units in FIG. 5 can also be implemented by different hardware in the computing device, for example, the determination unit 502 is determined by a part of the processing resources (for example, one core or two of the multi-core processors 101 in the at least one processor 101 in FIG. 1 ). The read/write unit 503 is implemented by the rest of the processing resources in the processor 101 in FIG. 1 (such as other cores in the multi-core processor), or by using a field-programmable gate array (FPGA, FPGA). ), or programmable devices such as coprocessors. The receiving unit 501 is realized by the network interface 103 in FIG. 1 . Obviously, the above-mentioned functional units can also be realized by a combination of software and hardware. For example, the determination unit 502 is realized by a hardware programmable device, and the read-write unit 503 is a software functional unit generated after the CPU reads the program code stored in the memory. .
本申请实施例,除非另有说明,“至少一个”的含义是指一个或多个。In the embodiments of the present application, unless otherwise specified, the meaning of "at least one" refers to one or more.
上述实施例可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行计算机程序指令时,全部或部分地产生按照本申请实施例描述的流程或功能。计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,计算机指令可以从一个网站站点、计算机、服务器或数据中心通过有线(例如同轴电缆、光纤、数字用户线(DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。计算机可读存储介质可以是计算机能够存取的任何可用介质或者是包含一个或多个可用介质集成的服务器、数据中心等数据存储设备。可用介质可以是磁性介质,(例如,软盘、硬盘、磁带)、光介质(例如,DVD)、或者半导体介质(例如固态硬盘Solid State Disk(SSD))等。The above-described embodiments may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented in whole or in part in the form of a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions described in accordance with the embodiments of the present application are generated in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable device. Computer instructions may be stored on or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server, or data center over a wire (e.g. coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (eg, infrared, wireless, microwave, etc.) to another website site, computer, server, or data center. A computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, a data center, or the like that includes an integration of one or more available media. Useful media may be magnetic media (eg, floppy disks, hard disks, magnetic tapes), optical media (eg, DVD), or semiconductor media (eg, Solid State Disk (SSD)), among others.
以上,以上实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的范围。Above, the above embodiments are only used to illustrate the technical solutions of the present application, but not to limit them; although the present application has been described in detail with reference to the above-mentioned embodiments, those of ordinary skill in the art should understand that: it can still be used for the above-mentioned implementations The technical solutions described in the examples are modified, or some technical features thereof are equivalently replaced; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.

Claims (23)

  1. 一种内存读写指令的执行方法,其特征在于,所述方法包括:A method for executing memory read and write instructions, wherein the method comprises:
    接收内存读写指令,所述内存读写指令携带目标内存空间的虚拟地址;receiving a memory read and write instruction, where the memory read and write instruction carries the virtual address of the target memory space;
    响应于所述虚拟地址对应的页表项包括镜像指示信息,根据所述虚拟地址确定主地址和镜像地址,所述镜像指示信息用于标识所述目标内存空间已启用内存镜像,所述主地址为所述目标内存空间中主内存空间的物理地址,所述镜像地址为所述目标内存空间中镜像内存空间的物理地址;In response to the page table entry corresponding to the virtual address including mirroring indication information, the main address and the mirroring address are determined according to the virtual address, the mirroring indication information being used to identify that the target memory space has enabled memory mirroring, and the main address is is the physical address of the main memory space in the target memory space, and the mirrored address is the physical address of the mirrored memory space in the target memory space;
    根据所述主地址和所述镜像地址,对所述主内存空间和所述镜像内存空间执行所述内存读写指令对应的操作。According to the main address and the mirror address, an operation corresponding to the memory read/write instruction is performed on the main memory space and the mirror memory space.
  2. 根据权利要求1所述的方法,其特征在于,所述镜像内存空间和所述主内存空间位于不同的通道。The method according to claim 1, wherein the mirrored memory space and the main memory space are located in different channels.
  3. 根据权利要求1或2所述的方法,其特征在于,所述镜像内存空间与所述主内存空间相隔至少一个缓存行尺寸的距离。The method according to claim 1 or 2, wherein the mirrored memory space is separated from the main memory space by a distance of at least one cache line size.
  4. 根据权利要求1至3中任一项所述的方法,其特征在于,所述主地址包括的偏移地址是根据缓存行尺寸以及所述虚拟地址包括的偏移地址确定的。The method according to any one of claims 1 to 3, wherein the offset address included in the main address is determined according to the size of the cache line and the offset address included in the virtual address.
  5. 根据权利要求1至4中任一项所述的方法,其特征在于,所述根据所述主地址和所述镜像地址,对所述主内存空间和所述镜像内存空间执行所述内存读写指令对应的操作,包括:The method according to any one of claims 1 to 4, wherein the memory read/write is performed on the main memory space and the mirrored memory space according to the main address and the mirrored address The operations corresponding to the instructions, including:
    响应于所述主地址对应的错误检查和纠正ECC空间以及所述镜像地址对应的ECC空间均包括所述镜像指示信息,根据所述主地址和所述镜像地址,对所述主内存空间和所述镜像内存空间执行所述内存读写指令对应的操作。In response to the error checking and correction ECC space corresponding to the main address and the ECC space corresponding to the mirror address including the mirror indication information, according to the main address and the mirror address, the main memory space and the mirror address are compared. The mirrored memory space executes operations corresponding to the memory read and write instructions.
  6. 根据权利要求1至5中任一项所述的方法,其特征在于,所述接收内存读写指令之前,所述方法还包括:The method according to any one of claims 1 to 5, wherein before the receiving a memory read and write instruction, the method further comprises:
    接收指定对象的内存分配请求;Receive a memory allocation request for the specified object;
    响应于所述指定对象的镜像标志置为设定值,为所述指定对象分配所述目标内存空间;Allocate the target memory space for the specified object in response to the mirroring flag of the specified object being set to a set value;
    其中,所述镜像标志在置为设定值时指示为指定对象分配包括主内存空间和镜像内存空间的内存空间。Wherein, when the mirror flag is set to a set value, it indicates to allocate a memory space including a main memory space and a mirror memory space for the specified object.
  7. 根据权利要求6所述的方法,其特征在于,所述接收指定对象的内存分配请求之后,所述方法还包括:The method according to claim 6, wherein after receiving the memory allocation request of the specified object, the method further comprises:
    向所述虚拟地址对应的页表项、所述主地址对应的ECC空间以及所述镜像地址对应的ECC空间分别写入所述镜像指示信息。The mirroring indication information is written into the page table entry corresponding to the virtual address, the ECC space corresponding to the main address, and the ECC space corresponding to the mirroring address, respectively.
  8. 根据权利要求6或7所述的方法,其特征在于,所述接收指定对象的内存分配请求之前,所述方法还包括:The method according to claim 6 or 7, wherein before the receiving a memory allocation request for the specified object, the method further comprises:
    响应于内存镜像指令,将所述指定对象的镜像标志修改为所述设定值,所述内存镜像指令指示针对所述指定对象所需的内存空间启用内存镜像。In response to a memory mirroring instruction, the mirroring flag of the specified object is modified to the set value, the memory mirroring instruction instructing to enable memory mirroring for the memory space required by the specified object.
  9. 根据权利要求1至8中任一项所述的方法,其特征在于,所述虚拟地址标识的每一个虚拟页对应于两个相邻的物理页。The method according to any one of claims 1 to 8, wherein each virtual page identified by the virtual address corresponds to two adjacent physical pages.
  10. 根据权利要求1至9中任一项所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 1 to 9, wherein the method further comprises:
    响应于所述镜像内存空间发生故障,隔离所述镜像内存空间;In response to the mirrored memory space failing, isolating the mirrored memory space;
    为所述虚拟地址重新分配镜像内存空间,将所述主内存空间保存的数据写入至重新分配的镜像内存空间。The mirrored memory space is reallocated for the virtual address, and the data stored in the main memory space is written into the reallocated mirrored memory space.
  11. 一种内存读写指令的执行装置,其特征在于,所述装置包括:A device for executing memory read and write instructions, wherein the device comprises:
    接收单元,用于接收内存读写指令,所述内存读写指令携带目标内存空间的虚拟地址;a receiving unit, configured to receive a memory read/write instruction, where the memory read/write instruction carries a virtual address of the target memory space;
    确定单元,用于响应于所述虚拟地址对应的页表项包括镜像指示信息,根据所述虚拟地址确定主地址和镜像地址,所述镜像指示信息用于标识所述目标内存空间已启用内存镜像,所述主地址为所述目标内存空间中主内存空间的物理地址,所述镜像地址为所述目标内存空间中镜像内存空间的物理地址;a determining unit, configured to determine a main address and a mirror address according to the virtual address in response to the page table entry corresponding to the virtual address including mirroring indication information, where the mirroring indication information is used to identify that memory mirroring has been enabled in the target memory space , the main address is the physical address of the main memory space in the target memory space, and the mirror address is the physical address of the mirrored memory space in the target memory space;
    读写单元,用于根据所述主地址和所述镜像地址,对所述主内存空间和所述镜像内存空间执行所述内存读写指令对应的操作。A read-write unit, configured to perform an operation corresponding to the memory read-write instruction on the main memory space and the mirrored memory space according to the main address and the mirror address.
  12. 根据权利要求11所述的装置,其特征在于,所述镜像内存空间和所述主内存空间位于不同的通道。The apparatus according to claim 11, wherein the mirrored memory space and the main memory space are located in different channels.
  13. 根据权利要求11或12所述的装置,其特征在于,所述镜像内存空间与所述主内存空间相隔至少一个缓存行尺寸的距离。The apparatus according to claim 11 or 12, wherein the mirrored memory space is separated from the main memory space by a distance of at least one cache line size.
  14. 根据权利要求11至13中任一项所述的装置,其特征在于,所述主地址包括的偏移地址是根据缓存行尺寸以及所述虚拟地址包括的偏移地址确定的。The apparatus according to any one of claims 11 to 13, wherein the offset address included in the main address is determined according to the size of the cache line and the offset address included in the virtual address.
  15. 根据权利要求11至14中任一项所述的装置,其特征在于,所述读写单元,用于响应于所述主地址对应的错误检查和纠正ECC空间以及所述镜像地址对应的ECC空间均包括所述镜像指示信息,根据所述主地址和所述镜像地址,对所述主内存空间和所述镜像内存空间执行所述内存读写指令对应的操作。The device according to any one of claims 11 to 14, wherein the read-write unit is configured to check and correct the ECC space corresponding to the main address and the ECC space corresponding to the mirror address in response to the error Both include the mirroring indication information, and according to the main address and the mirroring address, perform operations corresponding to the memory read and write instructions on the main memory space and the mirrored memory space.
  16. 根据权利要求11至15中任一项所述的装置,其特征在于,所述接收单元,还用于接收指定对象的内存分配请求;The device according to any one of claims 11 to 15, wherein the receiving unit is further configured to receive a memory allocation request for a specified object;
    所述装置还包括:分配单元,用于响应于所述指定对象的镜像标志置为设定值,为所述 指定对象分配所述目标内存空间;The device also includes: an allocation unit configured to allocate the target memory space for the specified object in response to the mirroring flag of the specified object being set to a set value;
    其中,所述镜像标志在置为设定值时指示为指定对象分配包括主内存空间和镜像内存空间的内存空间。Wherein, when the mirror flag is set to a set value, it indicates to allocate a memory space including a main memory space and a mirror memory space for the specified object.
  17. 根据权利要求16所述的装置,其特征在于,所述读写单元,还用于向所述虚拟地址对应的页表项、所述主地址对应的ECC空间以及所述镜像地址对应的ECC空间分别写入所述镜像指示信息。The device according to claim 16, wherein the read/write unit is further configured to send a page table entry corresponding to the virtual address, an ECC space corresponding to the main address, and an ECC space corresponding to the mirror address Write the mirroring indication information respectively.
  18. 根据权利要求16或17所述的装置,其特征在于,所述读写单元,还用于响应于内存镜像指令,将所述指定对象的镜像标志修改为所述设定值,所述内存镜像指令指示针对所述指定对象所需的内存空间启用内存镜像。The device according to claim 16 or 17, wherein the read-write unit is further configured to, in response to a memory mirroring instruction, modify the mirroring flag of the specified object to the set value, and the memory mirroring The instructions instruct to enable memory mirroring for the memory space required by the specified object.
  19. 根据权利要求11至18中任一项所述的装置,其特征在于,所述虚拟地址标识的每一个虚拟页对应于两个相邻的物理页。The apparatus according to any one of claims 11 to 18, wherein each virtual page identified by the virtual address corresponds to two adjacent physical pages.
  20. 根据权利要求11至19中任一项所述的装置,其特征在于,The device according to any one of claims 11 to 19, characterized in that:
    隔离单元,用于响应于所述镜像内存空间发生故障,隔离所述镜像内存空间;an isolation unit, configured to isolate the mirrored memory space in response to a failure of the mirrored memory space;
    所述装置还包括:分配单元,用于为所述虚拟地址重新分配镜像内存空间,所述读写单元,还用于将所述主内存空间保存的数据写入至重新分配的镜像内存空间。The apparatus further includes: an allocation unit, configured to reallocate a mirrored memory space for the virtual address, and the read-write unit, further configured to write the data stored in the main memory space into the reallocated mirrored memory space.
  21. 一种计算设备,其特征在于,所述计算设备包括处理器和存储器,所述存储器中存储有至少一条程序代码,所述程序代码由所述处理器加载并执行以实现如权利要求1至权利要求10任一项所述的方法。A computing device, characterized in that the computing device comprises a processor and a memory, the memory stores at least one piece of program code, and the program code is loaded and executed by the processor to implement claims 1 to 6 The method of any one of Claims 10.
  22. 一种计算设备,其特征在于,所述计算设备包括内存管理单元MMU、内存控制器MC和内存;A computing device, characterized in that the computing device comprises a memory management unit MMU, a memory controller MC and a memory;
    所述MMU,用于接收内存读写指令,所述内存读写指令携带目标内存空间的虚拟地址;The MMU is configured to receive memory read and write instructions, where the memory read and write instructions carry the virtual address of the target memory space;
    所述MMU,还用于响应于所述虚拟地址对应的页表项包括镜像指示信息,根据所述虚拟地址确定主地址和镜像地址,所述镜像指示信息用于标识所述目标内存空间已启用内存镜像,所述主地址为所述目标内存空间中主内存空间的物理地址,所述镜像地址为所述目标内存空间中镜像内存空间的物理地址;The MMU is further configured to determine the main address and the mirror address according to the virtual address in response to the page table entry corresponding to the virtual address including mirror indication information, where the mirror indication information is used to identify that the target memory space is enabled memory mirroring, the main address is the physical address of the main memory space in the target memory space, and the mirroring address is the physical address of the mirrored memory space in the target memory space;
    所述MC,用于根据所述主地址和所述镜像地址,对所述内存中的主内存空间和所述内存中的镜像内存空间执行所述内存读写指令对应的操作。The MC is configured to, according to the main address and the mirror address, perform operations corresponding to the memory read and write instructions on the main memory space in the memory and the mirror memory space in the memory.
  23. 一种计算机可读存储介质,其特征在于,所述存储介质中存储有至少一条程序代码,所述程序代码由处理器加载并执行以实现如权利要求1至权利要求10任一项所述的方法。A computer-readable storage medium, wherein at least one piece of program code is stored in the storage medium, and the program code is loaded and executed by a processor to implement the method according to any one of claims 1 to 10. method.
PCT/CN2021/140505 2021-03-16 2021-12-22 Method for executing memory read-write instruction, and computing device WO2022193768A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110281668.8A CN115080223A (en) 2021-03-16 2021-03-16 Execution method of memory read-write instruction and computing equipment
CN202110281668.8 2021-03-16

Publications (1)

Publication Number Publication Date
WO2022193768A1 true WO2022193768A1 (en) 2022-09-22

Family

ID=83246203

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/140505 WO2022193768A1 (en) 2021-03-16 2021-12-22 Method for executing memory read-write instruction, and computing device

Country Status (2)

Country Link
CN (1) CN115080223A (en)
WO (1) WO2022193768A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115373964A (en) * 2022-10-24 2022-11-22 北京智芯微电子科技有限公司 Memory out-of-range detection method, device, equipment and medium

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117670649A (en) * 2024-01-30 2024-03-08 南京砺算科技有限公司 Metadata writing and reading method and graphic processing unit

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120047340A1 (en) * 2010-08-20 2012-02-23 Canon Kabushiki Kaisha Information processing apparatus, method of controlling information processing apparatus, and program
CN107085535A (en) * 2017-03-30 2017-08-22 联想(北京)有限公司 A kind of information processing method and electronic equipment
CN110262893A (en) * 2019-05-16 2019-09-20 华为技术有限公司 The method, apparatus and computer storage medium of configuration mirroring memory
CN111400096A (en) * 2020-03-16 2020-07-10 杭州涂鸦信息技术有限公司 Memory mirroring method based on linux page missing mechanism and system and device thereof
CN112256396A (en) * 2020-10-23 2021-01-22 海光信息技术股份有限公司 Memory management method and system, security processing device and data processing device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120047340A1 (en) * 2010-08-20 2012-02-23 Canon Kabushiki Kaisha Information processing apparatus, method of controlling information processing apparatus, and program
CN107085535A (en) * 2017-03-30 2017-08-22 联想(北京)有限公司 A kind of information processing method and electronic equipment
CN110262893A (en) * 2019-05-16 2019-09-20 华为技术有限公司 The method, apparatus and computer storage medium of configuration mirroring memory
CN111400096A (en) * 2020-03-16 2020-07-10 杭州涂鸦信息技术有限公司 Memory mirroring method based on linux page missing mechanism and system and device thereof
CN112256396A (en) * 2020-10-23 2021-01-22 海光信息技术股份有限公司 Memory management method and system, security processing device and data processing device

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115373964A (en) * 2022-10-24 2022-11-22 北京智芯微电子科技有限公司 Memory out-of-range detection method, device, equipment and medium

Also Published As

Publication number Publication date
CN115080223A (en) 2022-09-20

Similar Documents

Publication Publication Date Title
US10180866B2 (en) Physical memory fault mitigation in a computing environment
EP2348413B1 (en) Controlling memory redundancy in a system
JP5484117B2 (en) Hypervisor and server device
US7644252B2 (en) Multi-processor system and memory accessing method
JP5574230B2 (en) Fault handling method and computer
WO2022193768A1 (en) Method for executing memory read-write instruction, and computing device
US8051333B2 (en) Memory failure recovery method, information processing apparatus, and program
JP4783392B2 (en) Information processing apparatus and failure recovery method
US20090024820A1 (en) Memory Allocation For Crash Dump
US7895477B2 (en) Resilience to memory errors with firmware assistance
WO2016115661A1 (en) Memory fault isolation method and device
US7734842B2 (en) Computer-implemented method, apparatus, and computer program product for managing DMA write page faults using a pool of substitute pages
US11409451B2 (en) Systems, methods, and storage media for using the otherwise-unutilized storage space on a storage device
US20120331261A1 (en) Point-in-Time Copying of Virtual Storage
US20170277632A1 (en) Virtual computer system control method and virtual computer system
US20230384947A1 (en) Dynamic repartition of memory physical address mapping
CN113127263B (en) Kernel crash recovery method, device, equipment and storage medium
US8892838B2 (en) Point-in-time copying of virtual storage and point-in-time dumping
US7293207B2 (en) Method for testing memory in a computer system utilizing a CPU with either 32-bit or 36-bit memory addressing
US9959278B1 (en) Method and system for supporting block-level incremental backups of file system volumes using volume pseudo devices
US8195981B2 (en) Memory metadata used to handle memory errors without process termination
WO2014024279A1 (en) Memory failure recovery device, method, and program
CN114840330A (en) Memory recovery method and device and control equipment
US11762573B2 (en) Preserving large pages of memory across live migrations of workloads
US20240070264A1 (en) Data storage device performing data protection and host device supporting a data protection function using a program context

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21931341

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21931341

Country of ref document: EP

Kind code of ref document: A1